{"record":{"id":"2b5a97243e4aeb9a","repo":"golang/go","slug":"duplicated-or-token","errorCode":null,"errorMessage":"duplicated '!' or '?' token","messagePattern":"duplicated '!' or '\\?' token","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/script/engine.go","lineNumber":370,"sourceCode":"\t\tquoted = false       // currently processing quoted text\n\t)\n\n\tflushArg := func() error {\n\t\tif len(rawArg) == 0 {\n\t\t\treturn nil // Nothing to flush.\n\t\t}\n\t\tdefer func() { rawArg = nil }()\n\n\t\tif cmd.name == \"\" && len(rawArg) == 1 && !rawArg[0].quoted {\n\t\t\targ := rawArg[0].s\n\n\t\t\t// Command prefix ! means negate the expectations about this command:\n\t\t\t// go command should fail, match should not be found, etc.\n\t\t\t// Prefix ? means allow either success or failure.\n\t\t\tswitch want := expectedStatus(arg); want {\n\t\t\tcase failure, successOrFailure:\n\t\t\t\tif cmd.want != \"\" {\n\t\t\t\t\treturn errors.New(\"duplicated '!' or '?' token\")\n\t\t\t\t}\n\t\t\t\tcmd.want = want\n\t\t\t\treturn nil\n\t\t\t}\n\n\t\t\t// Command prefix [cond] means only run this command if cond is satisfied.\n\t\t\tif strings.HasPrefix(arg, \"[\") && strings.HasSuffix(arg, \"]\") {\n\t\t\t\twant := true\n\t\t\t\targ = strings.TrimSpace(arg[1 : len(arg)-1])\n\t\t\t\tif strings.HasPrefix(arg, \"!\") {\n\t\t\t\t\twant = false\n\t\t\t\t\targ = strings.TrimSpace(arg[1:])\n\t\t\t\t}\n\t\t\t\tif arg == \"\" {\n\t\t\t\t\treturn errors.New(\"empty condition\")\n\t\t\t\t}\n\t\t\t\tcmd.conds = append(cmd.conds, condition{want: want, tag: arg})\n\t\t\t\treturn nil","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/script/engine.go#L352-L388","documentation":"Thrown by the script line parser (parse/flushArg) when a command line carries more than one expectation prefix token. The parser recognizes leading '!' (require failure) and '?' (allow either) and stores the first into cmd.want; a second such prefix is rejected because the intended expectation is ambiguous. This is a static syntax error surfaced at parse time before any command runs.","triggerScenarios":"A script line beginning with two expectation prefixes, e.g. `! ! cat file` or `! ? cat file` or `? ! cat file`. The second token hits the `cmd.want != \"\"` branch and returns the error.","commonSituations":"Script-test author mistakenly stacks modifiers believing '?' and '!' compose, or a copy-paste leaves a stray prefix. Also a typo where '!!' (shell history-style) is used instead of a single '!'.","solutions":["Use exactly one expectation prefix per line: either `! cmd` (expect failure) or `? cmd` (allow either) — never both.","Remove the duplicate prefix token.","If you need 'allow either' plus a condition, use `? [cond] cmd` rather than stacking prefixes."],"exampleFix":"// before\n! ! grep foo file\n# -> duplicated '!' or '?' token\n\n// after\n! grep foo file","handlingStrategy":"validation","validationCode":"// Validate a script line has at most one expectation prefix.\nfunc singleExpectationPrefix(line string) error {\n    t := strings.TrimSpace(line)\n    count := 0\n    for _, p := range []string{\"!\", \"?\"} {\n        if strings.HasPrefix(t, p) {\n            count++\n            t = strings.TrimSpace(t[len(p):])\n        }\n    }\n    if count > 1 { return errors.New(\"duplicated expectation prefix\") }\n    return nil\n}","typeGuard":"func isDuplicatePrefix(err error) bool {\n    return err != nil && err.Error() == \"duplicated '!' or '?' token\"\n}","tryCatchPattern":"// Static check: lint script files for double ! / ? prefixes before running.","preventionTips":["Use exactly one of '!' or '?' per line.","Lint script-test files for stacked prefixes.","Remember '!' and '?' do not compose."],"tags":["script","parser","test-framework","syntax-error"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}