{"record":{"id":"2f44c9de180d044a","repo":"jquense/yup","slug":"ref-must-be-a-non-empty-string","errorCode":null,"errorMessage":"ref must be a non-empty string","messagePattern":"ref must be a non-empty string","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/Reference.ts","lineNumber":38,"sourceCode":"export default class Reference<TValue = unknown> {\n  readonly key: string;\n  readonly isContext: boolean;\n  readonly isValue: boolean;\n  readonly isSibling: boolean;\n  readonly path: any;\n\n  readonly getter: (data: unknown) => unknown;\n  readonly map?: (value: unknown) => TValue;\n\n  declare readonly __isYupRef: boolean;\n\n  constructor(key: string, options: ReferenceOptions<TValue> = {}) {\n    if (typeof key !== 'string')\n      throw new TypeError('ref must be a string, got: ' + key);\n\n    this.key = key.trim();\n\n    if (key === '') throw new TypeError('ref must be a non-empty string');\n\n    this.isContext = this.key[0] === prefixes.context;\n    this.isValue = this.key[0] === prefixes.value;\n    this.isSibling = !this.isContext && !this.isValue;\n\n    let prefix = this.isContext\n      ? prefixes.context\n      : this.isValue\n      ? prefixes.value\n      : '';\n\n    this.path = this.key.slice(prefix.length);\n    this.getter = this.path && getter(this.path, true);\n    this.map = options.map;\n  }\n\n  getValue(value: any, parent?: {}, context?: {}): TValue {\n    let result = this.isContext ? context : this.isValue ? value : parent;","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/jquense/yup/blob/ff31eee8a2b10c938bb3a22544d9e33957a8cf01/src/Reference.ts#L20-L56","documentation":"After trimming, a Reference key must still contain characters — an empty (or whitespace-only) string points nowhere, so the constructor rejects it. This is a sibling check to the type check: the key was a string but had no meaningful content. Thrown at construction time with the message 'ref must be a non-empty string'.","triggerScenarios":"yup.ref('') or yup.ref('   ') — a whitespace-only string passes the typeof check but fails after `this.key = key.trim()`.","commonSituations":"Path variables from empty config values, empty form field names, split/join logic producing '' (e.g. ''.split('.') — though '' passes typeof), API responses with missing path fields.","solutions":["Provide the actual field name, e.g. yup.ref('endDate').","Validate/fall back on the path before constructing: if (!path) throw or use a default.","Check upstream data (config, form, API) for empty strings feeding the ref."],"exampleFix":"// before\nyup.ref(config.targetPath ?? '')\n// after\nif (!config.targetPath) throw new Error('targetPath is required');\nyup.ref(config.targetPath)","handlingStrategy":"validation","validationCode":"const refFrom = (path) => {\n  if (typeof path !== 'string' || path.trim() === '') throw new Error('ref path required');\n  return yup.ref(path);\n};","typeGuard":"const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":null,"preventionTips":["Check path.trim() before passing whitespace-prone inputs.","Provide fallback paths for optional config values instead of empty strings.","Add schema-building smoke tests that construct all refs at startup."],"tags":["yup","ref","empty-string","argument"],"backgroundTag":"invalid-ref-path","analyzedSha":"ff31eee8a2b10c938bb3a22544d9e33957a8cf01","analyzedAt":"2026-08-31T21:51:03.773Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}