Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWEEP: PrintStackTrace cleanup, #932 #1101

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/Lucene.Net.Benchmark/ByTask/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public Benchmark(TextReader algReader)
}
catch (Exception e) when (e.IsException())
{
//e.printStackTrace();
Console.Error.WriteLine(e.ToString());
e.PrintStackTrace();
throw new Exception("Error: cannot init PerfRunData!", e);
}

Expand Down Expand Up @@ -145,7 +144,7 @@ public static void Exec(string[] args)
}
catch (Exception e) when (e.IsException())
{
Console.Error.WriteLine(e.ToString());
e.PrintStackTrace();
Environment.Exit(1);
}

Expand All @@ -160,7 +159,7 @@ public static void Exec(string[] args)
catch (Exception e) when (e.IsException())
{
Console.Error.WriteLine("Error: cannot execute the algorithm! " + e.Message);
Console.Error.WriteLine(e.ToString());
e.PrintStackTrace();
}

Console.WriteLine("####################");
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Benchmark/ByTask/Feeds/EnwikiQueryMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static Query[] CreateQueries(IList<object> qs, Analyzer a)
}
catch (Exception e) when (e.IsException())
{
Console.Error.WriteLine(e.ToString());
e.PrintStackTrace();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Benchmark/ByTask/Feeds/ReutersQueryMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static Query[] CreateQueries(IList<object> qs, Analyzer a)
}
catch (Exception e) when (e.IsException())
{
Console.Error.WriteLine(e.ToString());
e.PrintStackTrace();
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/Lucene.Net.Benchmark/ByTask/Feeds/TrecContentSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Feeds
/// <list type="bullet">
/// <item><term>work.dir</term><description>specifies the working directory. Required if "docs.dir"
/// denotes a relative path (<b>default=work</b>).</description></item>
/// <item><term>docs.dir</term><description>specifies the directory where the TREC files reside.
/// <item><term>docs.dir</term><description>specifies the directory where the TREC files reside.
/// Can be set to a relative path if "work.dir" is also specified
/// (<b>default=trec</b>).
/// </description></item>
Expand Down Expand Up @@ -161,7 +161,7 @@ private void Read(StringBuilder buf, string lineStart,
internal virtual void OpenNextFile()
{
DoClose();
//currPathType = null;
//currPathType = null;
while (true)
{
if (nextFile >= inputFiles.Count)
Expand All @@ -181,7 +181,7 @@ internal virtual void OpenNextFile()
}
try
{
Stream inputStream = StreamUtils.GetInputStream(f); // support either gzip, bzip2, or regular text file, by extension
Stream inputStream = StreamUtils.GetInputStream(f); // support either gzip, bzip2, or regular text file, by extension
reader = new StreamReader(inputStream, m_encoding);
currPathType = TrecDocParser.PathType(f);
return;
Expand Down Expand Up @@ -234,7 +234,7 @@ private void DoClose() // LUCENENET specific - separate disposing from closing s
if (m_verbose)
{
Console.WriteLine("failed to dispose reader !");
Console.WriteLine(e.ToString());
e.PrintStackTrace(Console.Out);
}
}
reader = null;
Expand Down Expand Up @@ -275,7 +275,7 @@ public override DocData GetNextDocData(DocData docData)
docBuf.Length = 0;
Read(docBuf, DOC, false, false);

// save parsedFile for passing trecDataParser after the sync block, in
// save parsedFile for passing trecDataParser after the sync block, in
// case another thread will open another file in between.
parsedPathType = currPathType;

Expand All @@ -302,7 +302,7 @@ public override DocData GetNextDocData(DocData docData)
// count char length of text to be parsed (may be larger than the resulted plain doc body text).
AddBytes(docBuf.Length);

// This code segment relies on HtmlParser being thread safe. When we get
// This code segment relies on HtmlParser being thread safe. When we get
// here, everything else is already private to that thread, so we're safe.
docData = trecDocParser.Parse(docData, name, this, docBuf, parsedPathType);
AddItem();
Expand Down Expand Up @@ -367,7 +367,7 @@ public override void SetConfig(Config config)
{
m_encoding = Encoding.GetEncoding("iso-8859-1"); //StandardCharsets.ISO_8859_1.name();
}
// iteration exclusion in doc name
// iteration exclusion in doc name
excludeDocnameIteration = config.Get("content.source.excludeIteration", false);
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/Lucene.Net.Misc/Index/CompoundFileExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ public static void Main(string[] args)
}
catch (Exception ioe) when (ioe.IsIOException())
{
Console.Error.WriteLine(ioe.ToString());
//Console.Write(ioe.StackTrace);
ioe.PrintStackTrace();
}
finally
{
Expand All @@ -162,8 +161,7 @@ public static void Main(string[] args)
}
catch (Exception ioe) when (ioe.IsIOException())
{
Console.Error.WriteLine(ioe.ToString());
//Console.Write(ioe.StackTrace);
ioe.PrintStackTrace();
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Lucene.Net.Replicator/ReplicationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ private void WriteToInfoStream(string message)
/// </remarks>
protected virtual void HandleUpdateException(Exception exception)
{
WriteToInfoStream(string.Format("an error occurred during revision update: {0}", exception));
// LUCENENET specific - use utility method, and print full exception to be equivalent to printStackTrace in Java
WriteToInfoStream($"an error occurred during revision update: {exception}");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.Support;
using Lucene.Net.Support.Threading;
using Lucene.Net.Util;
using RandomizedTesting.Generators;
using System;
Expand Down Expand Up @@ -545,7 +544,7 @@ internal static void CheckResetException(Analyzer a, string input)
}
catch (Exception unexpected) when (unexpected.IsException())
{
unexpected.printStackTrace(Console.Error);
unexpected.PrintStackTrace(Console.Error);
Assert.Fail("Got wrong exception when Reset() not called: " + unexpected);
}
finally
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Lucene.Net.Index;
using Lucene.Net.Support;
using Lucene.Net.Util;
using Console = Lucene.Net.Util.SystemConsole;

Expand Down Expand Up @@ -81,4 +82,4 @@ protected override bool SortTermsByUnicode
}
}
#pragma warning restore 612, 618
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Lucene.Net.Index;
using Lucene.Net.Store;
using Lucene.Net.Support;
using Lucene.Net.Util;
using System;

Expand Down Expand Up @@ -65,4 +66,4 @@ protected internal override bool SortTermsByUnicode()
}
}
#pragma warning restore 612, 618
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ protected virtual void DoAfterIndexingThreadDone()
{
}

private ThreadJob[] LaunchIndexingThreads(LineFileDocs docs,
int numThreads,
long stopTime,
ISet<string> delIDs,
private ThreadJob[] LaunchIndexingThreads(LineFileDocs docs,
int numThreads,
long stopTime,
ISet<string> delIDs,
ISet<string> delPackIDs,
ConcurrentQueue<SubDocs> allSubDocs)
{
Expand Down Expand Up @@ -264,7 +264,7 @@ public override void Run()
outerInstance.m_delCount.AddAndGet(delSubDocs.SubIDs.Count);
if (Verbose)
{
Console.WriteLine(Thread.CurrentThread.Name + ": update pack packID=" + delSubDocs.PackID +
Console.WriteLine(Thread.CurrentThread.Name + ": update pack packID=" + delSubDocs.PackID +
" count=" + docsList.Count + " docs=" + string.Format(J2N.Text.StringFormatter.InvariantCulture, "{0}", docIDs));
}
outerInstance.UpdateDocuments(packIDTerm, docsList);
Expand All @@ -273,7 +273,7 @@ public override void Run()
{
if (Verbose)
{
Console.WriteLine(Thread.CurrentThread.Name + ": add pack packID=" + packID +
Console.WriteLine(Thread.CurrentThread.Name + ": add pack packID=" + packID +
" count=" + docsList.Count + " docs=" + string.Format(J2N.Text.StringFormatter.InvariantCulture, "{0}", docIDs));
}
outerInstance.AddDocuments(packIDTerm, docsList);
Expand Down Expand Up @@ -378,9 +378,8 @@ public override void Run()
catch (Exception t) when (t.IsThrowable())
{
Console.WriteLine(Thread.CurrentThread.Name + ": hit exc");
Console.WriteLine(t.ToString());
Console.Write(t.StackTrace);
outerInstance.m_failed.Value = (true);
outerInstance.m_failed.Value = true;
t.PrintStackTrace();
throw RuntimeException.Create(t);
}
}
Expand Down Expand Up @@ -536,8 +535,8 @@ public override void Run()
catch (Exception t) when (t.IsThrowable())
{
Console.WriteLine(Thread.CurrentThread.Name + ": hit exc");
outerInstance.m_failed.Value = (true);
Console.WriteLine(t.ToString());
outerInstance.m_failed.Value = true;
t.PrintStackTrace(Console.Out);
paulirwin marked this conversation as resolved.
Show resolved Hide resolved
throw RuntimeException.Create(t);
}
}
Expand Down Expand Up @@ -929,4 +928,4 @@ protected virtual void SmokeTestSearcher(IndexSearcher s)
RunQuery(s, pq);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ public override void Run()
catch (Exception t) when (t.IsThrowable())
{
Console.WriteLine("FAILED:");
Console.Out.WriteLine(t.StackTrace);
t.PrintStackTrace(Console.Out);
throw RuntimeException.Create(t);
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ internal virtual void MaybeThrowIOException(string message)
if (LuceneTestCase.Verbose)
{
Console.WriteLine(Thread.CurrentThread.Name + ": MockDirectoryWrapper: now throw random exception" + (message is null ? "" : " (" + message + ")"));
StackTraceHelper.PrintCurrentStackTrace(Console.Out);
}
throw new IOException("a random IOException" + (message is null ? "" : " (" + message + ")"));
}
Expand All @@ -505,15 +506,16 @@ internal virtual void MaybeThrowIOExceptionOnOpen(string name)
{
if (LuceneTestCase.Verbose)
{
Console.WriteLine(Thread.CurrentThread.Name + ": MockDirectoryWrapper: now throw random exception during open file=" + name);
Console.WriteLine(Thread.CurrentThread.Name + ": MockDirectoryWrapper: now throw random exception during open file=" + name);
StackTraceHelper.PrintCurrentStackTrace(Console.Out);
}
if (allowRandomFileNotFoundException == false || randomState.NextBoolean())
{
throw new IOException("a random IOException (" + name + ")");
}
else
{
throw randomState.NextBoolean() ? (IOException)new FileNotFoundException("a random IOException (" + name + ")") : new DirectoryNotFoundException("a random IOException (" + name + ")");
throw randomState.NextBoolean() ? new FileNotFoundException("a random IOException (" + name + ")") : new DirectoryNotFoundException("a random IOException (" + name + ")");
}
}
}
Expand Down Expand Up @@ -1038,7 +1040,7 @@ protected override void Dispose(bool disposing)
catch (Exception t) when (t.IsThrowable())
{
Console.Error.WriteLine("ERROR processing leftover segments file " + file + ":");
Console.WriteLine(t.ToString());
t.PrintStackTrace();
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/Lucene.Net.TestFramework/Store/MockIndexOutputWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Lucene.Net.Util;
using Lucene.Net.Support;
using Lucene.Net.Util;
using System;
using System.IO;
using System.Threading;
Expand Down Expand Up @@ -97,7 +98,7 @@ private void CheckDiskFull(byte[] b, int offset, DataInput @in, long len)
if (LuceneTestCase.Verbose)
{
Console.WriteLine(Thread.CurrentThread.Name + ": MDW: now throw fake disk full");
Console.WriteLine(Environment.StackTrace);
StackTraceHelper.PrintCurrentStackTrace(Console.Out);
}
throw new IOException(message);
}
Expand Down Expand Up @@ -199,4 +200,4 @@ public override string ToString()
return "MockIndexOutputWrapper(" + @delegate + ")";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Console = Lucene.Net.Util.SystemConsole;
using JCG = J2N.Collections.Generic;

namespace Lucene.Net
Expand Down Expand Up @@ -290,16 +289,6 @@ public static void retainAll<T>(this ISet<T> s, ISet<T> other)
}
}

public static void printStackTrace(this Exception e)
{
Console.Error.WriteLine(e.StackTrace);
}

public static void printStackTrace(this Exception e, TextWriter destination)
{
destination.WriteLine(e.StackTrace);
}

/// <summary>
/// Locates resources in the same directory as this type
/// </summary>
Expand Down
Loading
Loading