{"record":{"id":"66f3a2935641d67b","repo":"golang/go","slug":"errunexpectedsuccess","errorCode":"ErrUnexpectedSuccess","errorMessage":"unexpected success","messagePattern":"unexpected success","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/script/errors.go","lineNumber":14,"sourceCode":"// Copyright 2022 The Go Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style\n// license that can be found in the LICENSE file.\n\npackage script\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n)\n\n// ErrUnexpectedSuccess indicates that a script command that was expected to\n// fail (as indicated by a \"!\" prefix) instead completed successfully.\nvar ErrUnexpectedSuccess = errors.New(\"unexpected success\")\n\n// A CommandError describes an error resulting from attempting to execute a\n// specific command.\ntype CommandError struct {\n\tFile string\n\tLine int\n\tOp   string\n\tArgs []string\n\tErr  error\n}\n\nfunc cmdError(cmd *command, err error) *CommandError {\n\treturn &CommandError{\n\t\tFile: cmd.file,\n\t\tLine: cmd.line,\n\t\tOp:   cmd.name,\n\t\tArgs: cmd.args,\n\t\tErr:  err,","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/script/errors.go#L1-L32","documentation":"ErrUnexpectedSuccess is the sentinel raised by checkStatus when a script command prefixed with '!' (expect failure) instead completed successfully. It is the primary assertion-failure signal for negative tests in the script framework: the author asserted the command must fail, and it did not. The error is wrapped with the command's source location via cmdError.","triggerScenarios":"A script line `! cmd args` where cmd exits 0 / returns nil. checkStatus sees err == nil with cmd.want == failure and returns cmdError(cmd, ErrUnexpectedSuccess).","commonSituations":"The negative assertion was wrong (the command now succeeds), the environment changed so a previously-failing case now passes, or the '!' was added by mistake. Very common when updating tests: a fix makes a command succeed but the script still expects failure.","solutions":["Re-evaluate whether the command should still fail; if it should now succeed, remove the '!' prefix.","If the command should fail, tighten its input so it actually fails (e.g. pass an invalid flag or missing file).","Use errors.Is(err, script.ErrUnexpectedSuccess) in test harness code to distinguish this from other failures."],"exampleFix":"// before (script.txt)\n! go build ./brokenpkg\n# the package now builds -> unexpected success\n\n// after: either drop the negation\ngo build ./brokenpkg\n// or keep the package actually broken","handlingStrategy":"try-catch","validationCode":"// Negative assertions are static; review them when the underlying behavior changes.","typeGuard":"func isUnexpectedSuccess(err error) bool {\n    return errors.Is(err, script.ErrUnexpectedSuccess)\n}","tryCatchPattern":"if err := eng.Run(st, file); err != nil {\n    if errors.Is(err, script.ErrUnexpectedSuccess) {\n        // a '!'-prefixed command unexpectedly succeeded; revisit the assertion\n    }\n}","preventionTips":["Keep negative assertions ('!') tied to genuinely failing cases.","Revisit '!' lines whenever you fix the bug they guard.","Distinguish ErrUnexpectedSuccess from real failures in test harnesses."],"tags":["script","test-framework","assertion","negative-test","sentinel-error"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}