{"record":{"id":"1591451a07587576","repo":"avajs/ava","slug":"t-try-titles-must-be-strings","errorCode":null,"errorMessage":"`t.try()` titles must be strings","messagePattern":"`t\\.try\\(\\)` titles must be strings","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/test.js","lineNumber":114,"sourceCode":"\t\t\tif (test.isHook) {\n\t\t\t\tconst error = new Error('`t.try()` can only be used in tests');\n\t\t\t\ttest.saveFirstError(error);\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tconst {args, implementation, title} = parseTestArgs(attemptArgs);\n\n\t\t\tif (typeof implementation !== 'function') {\n\t\t\t\tthrow new TypeError('Expected an implementation.');\n\t\t\t}\n\n\t\t\tlet attemptTitle;\n\t\t\tif (!title.isSet || title.isEmpty) {\n\t\t\t\tattemptTitle = `${test.title} ─ attempt ${test.attemptCount + 1}`;\n\t\t\t} else if (title.isValid) {\n\t\t\t\tattemptTitle = `${test.title} ─ ${title.value}`;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError('`t.try()` titles must be strings');\n\t\t\t}\n\n\t\t\tif (!test.registerUniqueTitle(attemptTitle)) {\n\t\t\t\tthrow new Error(`Duplicate test title: ${attemptTitle}`);\n\t\t\t}\n\n\t\t\tlet committed = false;\n\t\t\tlet discarded = false;\n\n\t\t\tconst {assertCount, deferredSnapshotRecordings, errors, logs, passed, snapshotCount, startingSnapshotCount} = await test.runAttempt(attemptTitle, t => implementation(t, ...args));\n\n\t\t\treturn {\n\t\t\t\terrors,\n\t\t\t\tlogs: [...logs], // Don't allow modification of logs.\n\t\t\t\tpassed,\n\t\t\t\ttitle: attemptTitle,\n\t\t\t\tcommit({retainLogs = true} = {}) {\n\t\t\t\t\tif (committed) {","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/test.js#L96-L132","documentation":"The optional title given to t.try() must be a string. AVA parses the title from the arguments; if a non-string truthy value is passed in the title position (e.g. a number or object) and it cannot be interpreted as a valid title, this TypeError is thrown.","triggerScenarios":"t.try(42, impl) or t.try({label: 'x'}, impl) — a non-string first argument that is not a function; passing a title that is not a string or a function in the t.try(title, implementation, ...args) overload.","commonSituations":"Using template variables that resolved to a number; copying macros that accept titles as objects; TypeScript projects where `any` suppressed the type error until runtime.","solutions":["Pass the title as a string: t.try('my title', impl).","Remove the title entirely and let AVA generate 'attempt N' automatically.","Add a type check or TypeScript annotation so the title is always string."],"exampleFix":"// before\nconst attempt = t.try(123, impl);\n\n// after\nconst attempt = t.try('attempt 123', impl);","handlingStrategy":"type-guard","validationCode":"if (title !== undefined && typeof title !== 'string') throw new TypeError('t.try() title must be a string');","typeGuard":"const isValidTitle = (v) => v === undefined || typeof v === 'string';","tryCatchPattern":null,"preventionTips":["Quote titles as string literals","Avoid computing titles from non-string data without String() coercion","Type title params as string | undefined in helper wrappers"],"tags":["ava","t-try","title","typeerror"],"backgroundTag":"invalid-argument-value","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}