Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

util/config: assertRequiredString reports 'must be a string' when the property is missing, hiding 'required field omitted' errors

オープン 初心者向け
#67 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
84/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
typescript
領域
cli, tooling

調査の方向性

src/prompt-generators/util/config.ts の assertRequiredString から始め、bugzilla/config.ts、gitlab/config.ts、per-file.ts、json.ts の呼び出し元を確認します。src/util/test/load-cli-config.test.ts の関連するケース、特に 696 行目と 1283 行目を実行します。完了の条件は、キーが不足している場合はフィールドが必須であると報告され、型が誤っている場合は既存のメッセージが維持されることです。

索引モデルが issue の本文から書いたものです。

説明

bug S3

Observed behavior

assertRequiredString in src/prompt-generators/util/config.ts (lines 63-71) uses a single error message for two distinct failure modes:

export function assertRequiredString(
  value: Record<string, unknown>,
  key: string,
  field: string,
): void {
  if (!(key in value) || typeof value[key] !== 'string') {
    throw new Error(`${field} must be a string`);
  }
}

If the property is entirely missing from value, the user sees:

gitlab.search.project must be a string

That is the same message they would see if they had assigned a number, null, or an array to the field. A user who forgot to add project to their config (the most common configuration mistake for a required field) gets a message that suggests they assigned the wrong type, not that they omitted the field. The existing test in src/util/__test__/load-cli-config.test.ts at line 696 actually asserts this exact misleading message for a config where project is omitted entirely.

Expected behavior

The two failure modes should produce different messages, e.g.:

  • Missing key: gitlab.search.project is required
  • Wrong type: gitlab.search.project must be a string

This matches what other validators in the codebase already do for date fields (see assertRequiredDateField in bugzilla/config.ts, which also conflates the two cases but is less commonly hit). The downstream callers in bugzilla/config.ts, gitlab/config.ts, per-file.ts, and json.ts all funnel required-string validation through this helper, so fixing it once propagates.

Minimal reproduction

import { assertRequiredString } from './prompt-generators/util/config.js';

// Property entirely missing - error is misleading
assertRequiredString({}, 'foo', 'test.foo');
// Throws: \"test.foo must be a string\"  (should be \"test.foo is required\")

// Property has wrong type - error is accurate
assertRequiredString({ foo: 5 }, 'foo', 'test.foo');
// Throws: \"test.foo must be a string\"

Suggested fix

Split the check into two branches with distinct messages:

export function assertRequiredString(
  value: Record<string, unknown>,
  key: string,
  field: string,
): void {
  if (!(key in value)) {
    throw new Error(`${field} is required`);
  }
  if (typeof value[key] !== 'string') {
    throw new Error(`${field} must be a string`);
  }
}

Existing tests that match against the old message (e.g. load-cli-config.test.ts:696, :1283) would need to be updated to match the new "is required" message for missing-key cases.

Severity

S3 - confusing API. The behaviour is correct (the error is thrown), but the message misleads users about what they did wrong.

主要言語
TypeScript
スター
2
フォーク
1
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

joewalker/loop-the-loop のほかの issue

joewalker/loop-the-loop の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。