{"record":{"id":"e62f0098c26d81d9","repo":"evanw/esbuild","slug":"should-be-string-or-array-of-strings","errorCode":null,"errorMessage":"Should be string or array of strings","messagePattern":"Should be string or array of strings","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/terser-tests.js","lineNumber":285,"sourceCode":"    }\n    throw new Error(\"Should be boolean\");\n  }\n\n  function read_string(stat) {\n    if (stat.TYPE == \"SimpleStatement\") {\n      var body = stat.body;\n      switch (body.TYPE) {\n        case \"String\":\n          return body.value;\n        case \"Array\":\n          return body.elements.map(function (element) {\n            if (element.TYPE !== \"String\")\n              throw new Error(\"Should be array of strings\");\n            return element.value;\n          }).join(\"\\n\");\n      }\n    }\n    throw new Error(\"Should be string or array of strings\");\n  }\n\n  function get_one_test(name, block) {\n    var test = {\n      name: name,\n      options: {},\n      reminify: true,\n    };\n    var tw = new U.TreeWalker(function (node, descend) {\n      if (node instanceof U.AST_Assign) {\n        if (!(node.left instanceof U.AST_SymbolRef)) {\n          croak(node);\n        }\n        var name = node.left.name;\n        test[name] = evaluate(node.right);\n        return true;\n      }\n      if (node instanceof U.AST_LabeledStatement) {","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/scripts/terser-tests.js#L267-L303","documentation":"Thrown by read_string() in scripts/terser-tests.js:285 as the final fallback. read_string() accepts only a SimpleStatement whose body is an AST_String or an AST_Array (of strings). If the statement is not a SimpleStatement, or its body is any other node type (number, regex, call, object literal, etc.), this error fires.","triggerScenarios":"Assigning a non-string value to a string field, e.g. `expect_exact: 42;`, `node_version: /v\\d+/;`, or `expect: someVar;`. Also hit if the value is wrapped in a way that changes the node type away from a plain SimpleStatement.","commonSituations":"Contributor uses a number, regex literal, identifier, or function call where the harness expects a string or array of strings (for fields routed through read_string such as expect_exact / node_version).","solutions":["Wrap the value in quotes: `expect_exact: \"var a=1;\";`.","If the value is already text but multi-line, use the array form: `expect_exact: [\"line1\", \"line2\"];`.","Move genuinely non-string data to a field whose reader accepts that type (read_boolean for booleans)."],"exampleFix":"// before\nexpect_exact: 42;\n\n// after\nexpect_exact: \"42\";","handlingStrategy":"type-guard","validationCode":"function isAcceptableStringField(stat) {\n  if (stat.TYPE !== 'SimpleStatement') return false;\n  const b = stat.body;\n  return b instanceof U.AST_String || (b instanceof U.AST_Array && b.elements.every(e => e instanceof U.AST_String));\n}","typeGuard":"const isStringOrStringArray = (stat) =>\n  stat.TYPE === 'SimpleStatement' &&\n  (stat.body instanceof U.AST_String ||\n   (stat.body instanceof U.AST_Array && stat.body.elements.every(e => e.TYPE === 'String')));","tryCatchPattern":"try { read_string(stat); }\ncatch (e) {\n  if (/Should be string or array of strings/.test(e.message)) console.error('Use a string literal or array of string literals');\n  throw e;\n}","preventionTips":["Quote all string field values.","Use the array form only for multi-line strings, with every element quoted."],"tags":["test-harness","terser","validation","string","contributor"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}