Skip to content

Commit e5a906d

Browse files
committed
Exit codes for regular parsing
Exit code = number of errors (+ number of warnings, if warningsAreErrors = true) Works for regular; TODO: implement for xic and query
1 parent 8eb3b34 commit e5a906d

File tree

5 files changed

+64
-13
lines changed

5 files changed

+64
-13
lines changed

MainClass.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,10 @@ private static void RegularParametersParsing(string[] args)
447447
"N|noiseData", "Include noise data in mzML output",
448448
v => parseInput.NoiseData = v != null
449449
},
450+
{
451+
"w|warningsAreErrors", "Return non-zero exit code for warnings; default only for errors",
452+
v => parseInput.Vigilant = v != null
453+
},
450454
{
451455
"u:|s3_url:",
452456
"Optional property to write directly the data into S3 Storage.",
@@ -677,7 +681,9 @@ private static void RegularParametersParsing(string[] args)
677681

678682
RawFileParser.Parse(parseInput);
679683

680-
exitCode = 0;
684+
Log.Info($"Processing completed {parseInput.Errors} errors, {parseInput.Warnings} warnings");
685+
686+
exitCode = parseInput.Vigilant ? parseInput.Errors + parseInput.Warnings: parseInput.Errors;
681687
}
682688
catch (UnauthorizedAccessException ex)
683689
{

ParseInput.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public class ParseInput
1414
/// </summary>
1515
private string _rawFilePath;
1616

17+
private int _errors;
18+
19+
private int _warnings;
20+
1721
/// <summary>
1822
/// The RAW folder path.
1923
/// </summary>
@@ -32,6 +36,15 @@ public string RawFilePath
3236
}
3337
}
3438

39+
public int Errors
40+
{
41+
get => _errors;
42+
}
43+
public int Warnings
44+
{
45+
get => _warnings;
46+
}
47+
3548
/// <summary>
3649
/// The output directory.
3750
/// </summary>
@@ -82,6 +95,8 @@ public string RawFilePath
8295

8396
public bool StdOut { get; set; }
8497

98+
public bool Vigilant { get; set; }
99+
85100
private S3Loader S3Loader { get; set; }
86101

87102
public string S3AccessKeyId { get; set; }
@@ -111,6 +126,9 @@ public ParseInput()
111126
MgfPrecursor = false;
112127
StdOut = false;
113128
NoiseData = false;
129+
Vigilant = false;
130+
_errors = 0;
131+
_warnings = 0;
114132
}
115133

116134
public ParseInput(string rawFilePath, string rawDirectoryPath, string outputDirectory, OutputFormat outputFormat
@@ -127,5 +145,15 @@ public void InitializeS3Bucket()
127145
{
128146
S3Loader = new S3Loader(S3Url, S3AccessKeyId, S3SecretAccessKey, BucketName);
129147
}
148+
149+
public void NewError()
150+
{
151+
_errors++;
152+
}
153+
154+
public void NewWarn()
155+
{
156+
_warnings++;
157+
}
130158
}
131159
}

RawFileParser.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,26 @@ private static void TryProcessFile(ParseInput parseInput)
6161
{
6262
ProcessFile(parseInput);
6363
}
64-
catch (UnauthorizedAccessException ex)
65-
{
66-
Log.Error(!ex.Message.IsNullOrEmpty()
67-
? ex.Message
68-
: "Attempting to write to an unauthorized location.");
69-
}
64+
7065
catch (Exception ex)
7166
{
72-
if (ex is RawFileParserException)
67+
if (ex is UnauthorizedAccessException)
68+
{
69+
Log.Error(!ex.Message.IsNullOrEmpty()
70+
? ex.Message
71+
: "Attempting to write to an unauthorized location.");
72+
parseInput.NewError();
73+
}
74+
else if (ex is RawFileParserException)
7375
{
7476
Log.Error(ex.Message);
77+
parseInput.NewError();
7578
}
7679
else
7780
{
78-
Log.Error("An unexpected error occured while parsing file:" + parseInput.RawFilePath);
81+
Log.Error("An unexpected error occured (see below)");
7982
Log.Error(ex.ToString());
83+
parseInput.NewError();
8084
}
8185
}
8286
}

Writer/MgfSpectrumWriter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
8383
catch (Exception ex)
8484
{
8585
Log.WarnFormat("Cannot load trailer infromation for scan {0} due to following exception\n{1}", scanNumber, ex.Message);
86+
ParseInput.NewWarn();
8687
trailerData = new ScanTrailer();
8788
}
8889

@@ -141,9 +142,14 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
141142
}
142143

143144
if (_precursorScanNumber > 0)
145+
{
144146
precursorReference = ConstructSpectrumTitle((int)Device.MS, 1, _precursorScanNumber);
147+
}
145148
else
149+
{
146150
Log.Error($"Failed finding precursor for {scanNumber}");
151+
ParseInput.NewError();
152+
}
147153
}
148154
}
149155

Writer/MzMlSpectrumWriter.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
591591
catch (Exception ex)
592592
{
593593
Log.Error(ex);
594+
ParseInput.NewError();
594595
}
595596
}
596597

@@ -665,16 +666,17 @@ private void PopulateInstrumentConfigurationList(int firstScanNumber, int lastSc
665666
OntologyMapping.IonizationTypes[scanFilter.IonizationMode]);
666667
}
667668
}
668-
catch (Exception e)
669+
catch (Exception)
669670
{
670671
if (!ParseInput.IgnoreInstrumentErrors)
671672
{
672-
Log.ErrorFormat("Unsupported Ionization Mode - {0}; Use ignoreInstrumentErrors key to suppress this error", scanFilter.IonizationMode.ToString());
673-
throw e;
673+
Log.ErrorFormat("Unsupported ionization mode - {0}; Use ignoreInstrumentErrors key to suppress this error", scanFilter.IonizationMode.ToString());
674+
throw;
674675
}
675676
else
676677
{
677678
Log.WarnFormat("Unsupported Ionization Mode - {0}", scanFilter.IonizationMode.ToString());
679+
ParseInput.NewWarn();
678680
}
679681
}
680682

@@ -694,12 +696,13 @@ private void PopulateInstrumentConfigurationList(int firstScanNumber, int lastSc
694696
{
695697
if (!ParseInput.IgnoreInstrumentErrors)
696698
{
697-
Log.ErrorFormat("No Scan Filter found for the following scan {0}; Use ignoreInstrumentErrors key to suppress", scanNumber);
699+
Log.ErrorFormat("No scan filter found for the following scan {0}; Use ignoreInstrumentErrors key to suppress", scanNumber);
698700
throw;
699701
}
700702
else
701703
{
702704
Log.WarnFormat("No Scan Filter found for the following scan {0}", scanNumber);
705+
ParseInput.NewWarn();
703706
}
704707
}
705708

@@ -1201,6 +1204,7 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
12011204
catch (Exception ex)
12021205
{
12031206
Log.WarnFormat("Cannot load trailer infromation for scan {0} due to following exception\n{1}", scanNumber, ex.Message);
1207+
ParseInput.NewWarn();
12041208
trailerData = new ScanTrailer();
12051209
}
12061210

@@ -1325,6 +1329,7 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
13251329
};
13261330

13271331
Log.Error($"Failed finding precursor for {scanNumber}");
1332+
ParseInput.NewError();
13281333
}
13291334
}
13301335
else
@@ -2129,6 +2134,7 @@ private PrecursorListType ConstructPrecursorList(int precursorScanNumber, IScanE
21292134
catch (ArgumentOutOfRangeException)
21302135
{
21312136
Log.Warn($"Failed to get reaction when parsing precursor {precursorScanNumber}");
2137+
ParseInput.NewWarn();
21322138
}
21332139

21342140
var precursor = new PrecursorType
@@ -2315,6 +2321,7 @@ private PrecursorListType ConstructPrecursorList(int precursorScanNumber, IScanE
23152321

23162322
default:
23172323
Log.Warn($"Unknown supplemental activation type: {reaction.ActivationType}");
2324+
ParseInput.NewWarn();
23182325
break;
23192326

23202327
}

0 commit comments

Comments
 (0)