Hosting Operations
Show Context Around the First Error
A log contains a clear error line, but the useful cause may be several lines above or below it.
Command
grep -RInC 3 -m 1 'ERROR' artifacts logs
What changed
Nothing changes. grep prints the first ERROR match with nearby lines.
Danger
safe
When to use it
Use after finding which logs contain error markers.
When not to use it
Do not stop at the first match if the job continued and later failed for another reason.
Undo or recovery
No undo needed because this command is read-only.
Expected output
A small context block around the first ERROR match.
demo script
Disposable terminal steps
cd /lab/ci-artifacts && grep -RIn 'ERROR' artifacts logscd /lab/ci-artifacts && grep -RInC 3 -m 1 'ERROR' artifacts logscd /lab/ci-artifacts && sed -n '1,12p' artifacts/build/app-build.log
simulated output
What it looks like
::fixture-ready::
$ cd /lab/ci-artifacts && grep -RIn 'ERROR' artifacts logs
artifacts/build/webpack.log:4:ERROR Module not found: Cannot resolve ./missing-module
artifacts/build/app-build.log:4:ERROR in src/server.ts:42: missing export createServer
artifacts/coverage/coverage-summary.txt:5:ERROR coverage below minimum threshold: statements 78.4 < 80.0
::exit-code::0
$ cd /lab/ci-artifacts && grep -RInC 3 -m 1 'ERROR' artifacts logs
artifacts/build/webpack.log-1-webpack 5.91.0 compiled with 1 error
artifacts/build/webpack.log-2-asset main.js 245 KiB
artifacts/build/webpack.log-3-asset vendor.js 812 KiB
artifacts/build/webpack.log:4:ERROR Module not found: Cannot resolve ./missing-module
--
artifacts/build/app-build.log-1-Starting build
artifacts/build/app-build.log-2-Resolving dependencies
artifacts/build/app-build.log-3-Compiling app
artifacts/build/app-build.log:4:ERROR in src/server.ts:42: missing export createServer
artifacts/build/app-build.log-5-Build failed with exit code 1
--
artifacts/coverage/coverage-summary.txt-2-Statements: 78.4%
artifacts/coverage/coverage-summary.txt-3-Branches: 71.2%
artifacts/coverage/coverage-summary.txt-4-Functions: 81.0%
artifacts/coverage/coverage-summary.txt:5:ERROR coverage below minimum threshold: statements 78.4 < 80.0
::exit-code::0
$ cd /lab/ci-artifacts && sed -n '1,12p' artifacts/build/app-build.log
Starting build
Resolving dependencies
Compiling app
ERROR in src/server.ts:42: missing export createServer
Build failed with exit code 1
::exit-code::0
YouTube Short
Read around the error.
The failing line is rarely enough. Print a few lines of context so the cause is visible.
LinkedIn hook
The line before the error often explains the error.
Question: Do you read only the error line, or the context around it?
experiments
A/B tests to run
Metric: short_completion_rate
A: The line before the error often explains the error.
B: Print context before debugging a CI error.