{"record":{"id":"d77792f917d28213","repo":"jackwener/OpenCLI","slug":"oeis-label-cannot-be-empty","errorCode":null,"errorMessage":"oeis ${label} cannot be empty","messagePattern":"oeis (.+?) cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/oeis/utils.js","lineNumber":16,"sourceCode":"// Shared helpers for the OEIS adapter (Online Encyclopedia of Integer Sequences).\n//\n// OEIS exposes a single search endpoint that handles both keyword search and\n// id lookup via `q=id:Annnnnn`. JSON output via `fmt=json`. No API key.\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\nexport const OEIS_BASE = 'https://oeis.org';\nconst UA = 'opencli-oeis-adapter/1.0 (+https://github.com/jackwener/opencli; mailto:opencli@example.com)';\n\n// OEIS ids are A followed by 6 zero-padded digits (older entries use 6 by convention,\n// modern entries can be longer; OEIS itself accepts any digits after A).\nconst SEQUENCE_ID_PATTERN = /^A\\d{1,7}$/;\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`oeis ${label} cannot be empty`);\n    return s;\n}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\n    const raw = value ?? defaultValue;\n    const n = typeof raw === 'number' ? raw : Number(raw);\n    if (!Number.isInteger(n) || n <= 0) {\n        throw new ArgumentError(`oeis ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`oeis ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport function requireSequenceId(value) {\n    const raw = String(value ?? '').trim().toUpperCase();\n    if (!raw) throw new ArgumentError('oeis sequence id is required (e.g. \"A000045\" for Fibonacci)');","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/oeis/utils.js#L1-L34","documentation":"This ArgumentError is thrown by requireString in clis/oeis/utils.js when a labeled string argument is empty or only whitespace after String() coercion and trimming. It guards OEIS command inputs (e.g. the search query) so an empty request never hits the OEIS API.","triggerScenarios":"Calling the oeis search command with a missing, empty (\"\"), or whitespace-only id/query value — e.g. `oeis search \"\"` or args.id being undefined when requireString(value, 'query') is invoked from query().","commonSituations":"Shell variable interpolation producing an empty string (unset env var), quoting mistakes that pass an empty argument, scripted calls where a prior step yielded nothing, or forgetting the positional argument entirely.","solutions":["Supply a non-empty query/id argument to the command.","Check that any shell variable feeding the argument is set and non-empty (\"${VAR:?}\").","Trim and validate user input before invoking the command.","If the upstream value can be legitimately absent, handle that before calling rather than passing it through."],"exampleFix":"// before (VAR empty)\noeis search \"$QUERY\"\n// after\noeis search \"${QUERY:?QUERY must not be empty}\"","handlingStrategy":"validation","validationCode":"const q = String(raw ?? '').trim();\nif (!q) throw new Error('oeis query must be a non-empty string');","typeGuard":"const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try { return await oeisSearch(raw); } catch (e) { if (e instanceof ArgumentError && /cannot be empty/.test(e.message)) { console.error('Provide a non-empty query'); process.exitCode = 2; return; } throw e; }","preventionTips":["Use ${VAR:?msg} in shell to fail fast on empty variables.","Trim and check arguments before invoking OEIS commands.","Handle missing positional args in wrappers around the CLI.","Never pass user input straight through without an emptiness check."],"tags":["validation","input-error","oeis","empty-argument"],"backgroundTag":"empty-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}