/// <inheritdoc /> protected override bool ReadChunk(Stream stream, out MemoryStream chunk) { chunk = null; var bytes = new byte[4]; if (stream.Read(bytes, 0, 4) == 0) { return(false); } int length = BitConverter.ToInt32(bytes, 0); if (length <= 0 || length > BlockSize * 2) { UserErrorException.ThrowUserErrorException("Invalid input file format"); } var buffer = new byte[length]; if (stream.Read(buffer, 0, length) < length) { UserErrorException.ThrowUserErrorException("Invalid input file format. File is too short"); } chunk = new MemoryStream(buffer); return(true); }
public void UserError() { var exception = new UserErrorException("user error"); var observedExitCode = ExitCodeUtilities.ShowException(exception); Assert.Equal((int)ExitCodes.UserError, observedExitCode); }
public static void ValidateScoreValue(string value, string line) { if (double.TryParse(value, out _)) { return; } var e = new UserErrorException( $"{value} is not a valid score value. Scores are expected to be numbers."); e.Data["Line"] = line; throw e; }
/// <summary> /// Rethrows exception to be shown to user in some specific cases /// </summary> public static void ConvertFileExceptions(this Exception exception) { switch (exception) { case IOException _: case UnauthorizedAccessException _: case InvalidDataException _: //this is gzip case //SecurityException _: //should not be thrown in normal run case: UserErrorException.ThrowUserErrorException($"Error processing file: {exception.Message}"); break; } }
public static void Main(string[] args) { ExceptionManager.EnsureManagerInitialized(); args = args.Where(str => !string.IsNullOrEmpty(str)).ToArray(); if (args.Length != 3) { UserErrorException.ThrowUserErrorException("There should be 3 arguments"); } bool compress = ParseMode(args[0]); string inputPath = args[1]; string outputPath = args[2]; ZipZipProcessing.Process(inputPath, outputPath, compress); }
public static bool RunTest(string toolchainName, Compiler compile, Exe runner, File source) { var destPath = tests_results.Combine(source); var sourcePath = tests.Combine(source); var expected = sourcePath.DropExtension().Combine(Ext(".o")); Console.Write($"\x1b[KRunning test {source} ({toolchainName}) "); destPath.DirName().Create(); UserErrorException exception = null; try { CompileToFile(compile, sourcePath, destPath); } catch (UserErrorException e) { exception = e; } if (exception != null) { Console.WriteLine(""); Console.WriteLine("\x1b[1;31mFail\x1b[m"); Console.WriteLine($"\x1b[1;33m{exception.Message}\x1b[m\n"); return(false); } else { var actualStr = runner.Run(destPath); var expectedStr = expected.Read(); if (actualStr != expectedStr) { Console.WriteLine("\x1b[1;31mFail\x1b[m"); Console.WriteLine($"\x1b[1;33m{source}: expected {expectedStr} but got {actualStr}.\x1b[m\n"); return(false); } else { Console.Write("\x1b[1;32mOK\x1b[m\n"); // \r at the end for quiet return(true); } } }
internal void ParseHeaderLines() { string line; while ((line = _reader.ReadLine()) != null) { if (line.StartsWith("#geneSymbol")) { break; } line = line.Trim(); (string key, string value) = line.OptimizedKeyValue(); switch (key) { case "#title": JsonTag = value; break; case "#version": Version = value; break; case "#description": DataSourceDescription = value; break; default: var e = new UserErrorException("Unexpected header tag observed"); e.Data[ExitCodeUtilities.Line] = line; throw e; } } _tags = ParserUtilities.ParseTags(line, "#geneSymbol", NumRequiredColumns); CheckTagsAndSetJsonKeys(); Categories = ParserUtilities.ParseCategories(_reader.ReadLine(), NumRequiredColumns, _numAnnotationColumns, _annotationValidators); Descriptions = ParserUtilities.ParseDescriptions(_reader.ReadLine(), NumRequiredColumns, _numAnnotationColumns); ValueTypes = ParserUtilities.ParseTypes(_reader.ReadLine(), NumRequiredColumns, _numAnnotationColumns); }
private void PrintError(UserErrorException e) { Console.SetForegroundColor(ConsoleColor.Red); Console.WriteLine($"Error: {e.Message}"); Console.SetForegroundColor(ConsoleColor.Gray); }