diff --git a/src/cli.nim b/src/cli.nim index 2e3f76c1..b4f3e470 100644 --- a/src/cli.nim +++ b/src/cli.nim @@ -304,7 +304,7 @@ proc showHelp(exitCode: range[0..255] = 0, prependDashedLine = false) = let f = if exitCode == 0: stdout else: stderr if prependDashedLine: let dashLen = helpUncompressed.firstLine().len - f.write(&"\n\n{'-'.repeat(dashLen)}\n\n") + f.write(&"\n{'-'.repeat(dashLen)}\n\n") f.writeLine helpUncompressed if f == stdout: f.flushFile() @@ -323,14 +323,17 @@ let colorStdout* = shouldUseColor(stdout) colorStderr* = shouldUseColor(stderr) -proc showError*(s: string) = +proc showError*(s: string, writeHelp = true) = const errorPrefix = "Error: " if colorStderr: stderr.styledWrite(fgRed, errorPrefix) else: stderr.write(errorPrefix) - stderr.write(s) - showHelp(exitCode = 1, prependDashedLine = true) + stderr.writeLine(s) + if writeHelp: + showHelp(exitCode = 1, prependDashedLine = true) + else: + quit 1 func formatOpt(kind: CmdLineKind, key: string, val = ""): string = ## Returns a string that describes an option, given its `kind`, `key` and diff --git a/src/sync/probspecs.nim b/src/sync/probspecs.nim index e37b3f40..953efccb 100644 --- a/src/sync/probspecs.nim +++ b/src/sync/probspecs.nim @@ -158,9 +158,26 @@ proc validate(probSpecsDir: ProbSpecsDir, conf: Conf) = # `fetch` and `merge` separately, for better error messages. logNormal(&"Updating cached 'problem-specifications' data...") - discard gitCheck(0, ["fetch", "--quiet", remoteName, mainBranchName], - &"failed to fetch '{mainBranchName}' in " & - &"problem-specifications directory: '{probSpecsDir}'") + try: + discard gitCheck(0, ["fetch", "--quiet", remoteName, mainBranchName], + &"failed to fetch '{mainBranchName}' in " & + &"problem-specifications directory: '{probSpecsDir}'") + except OSError: + const msg = """ + Unable to update the problem-specifications cache. + + You can either: + + - ensure that you have network connectivity, and run the same configlet command again + - or add the '--offline' option to skip updating the cache + + The most recent commit in the problem-specifications cache is: + + """.unindent() + const format = "commit %H%nAuthor: %an <%ae>%nCommitDate: %cD%n%n %s" + let mostRecentCommit = gitCheck(0, ["log", "-n1", + &"--format={format}"]).strip().indent(4) + showError(msg & mostRecentCommit, writeHelp = false) discard gitCheck(0, ["merge", "--ff-only", &"{remoteName}/{mainBranchName}"], &"failed to merge '{mainBranchName}' in " &