Harden Go CLI subprocess behavior
This commit is contained in:
@@ -26,7 +26,7 @@ var processRunner = func(inv processInvocation, stdout io.Writer) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := coreio.ValidateWellFormedJSON(transcriptBytes); err != nil {
|
||||
if err := coreio.ValidateWellFormedJSON(inv.TranscriptPath, transcriptBytes); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := coreio.ReadRequiredFile(inv.GlossaryPath, "glossary"); err != nil {
|
||||
|
||||
@@ -156,7 +156,7 @@ func TestRunProcessMalformedTranscriptJSON(t *testing.T) {
|
||||
if stdout.Len() != 0 {
|
||||
t.Fatalf("expected empty stdout, got %q", stdout.String())
|
||||
}
|
||||
if !strings.Contains(stderr.String(), "transcript file is not valid JSON") {
|
||||
if !strings.Contains(stderr.String(), "is not valid JSON") {
|
||||
t.Fatalf("expected malformed transcript error, got %q", stderr.String())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ func ReadRequiredFile(path string, label string) ([]byte, error) {
|
||||
return contents, nil
|
||||
}
|
||||
|
||||
func ValidateWellFormedJSON(raw []byte) error {
|
||||
func ValidateWellFormedJSON(path string, raw []byte) error {
|
||||
if !json.Valid(raw) {
|
||||
return fmt.Errorf("transcript file is not valid JSON")
|
||||
return fmt.Errorf("transcript file %q is not valid JSON", path)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user