When `asString` receives `undefined` an exception is thrown
メンテナーはふだん 2 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- javascript, node.js
調査の方向性
失敗は lib/serializer.js の Serializer.asString、103-113 行目付近で報告されています。そこから始め、null と undefined の意図されたセマンティクスを確認するために、関連する issue と pull request を確認してください。Fastify のレスポンスケースを再現し、選択した挙動のカバレッジを追加して、配列レスポンスで例外が発生しなくなったことを確認してください。
索引モデルが issue の本文から書いたものです。
説明
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.24.3
Plugin version
5.9.1
Node.js version
20.2.0
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Ubuntu 22.04.1
Description
Not entirely sure this is a bug, could be intended behavior.
I have an array of stings, however one of the elements is undefined.
['test1', 'test2', 'test3', undefined]
If I return that from a fastify endpoint, asString throws an exception:
TypeError: Cannot read properties of undefined (reading 'toString')
at Serializer.asString (/repo/node_modules/fast-json-stringify/lib/serializer.js:113:19)
at anonymous1 (eval at build (/repo/node_modules/fast-json-stringify/index.js:190:23), <anonymous>:17:28)
at anonymous0 (eval at build (/repo/node_modules/fast-json-stringify/index.js:190:23), <anonymous>:52:19)
at serialize (/repo/node_modules/fastify/lib/reply.js:896:12)
at preSerializationHookEnd (/repo/node_modules/fastify/lib/reply.js:516:17)
at preSerializationHook (/repo/node_modules/fastify/lib/reply.js:500:5)
at Reply.send (/repo/node_modules/fastify/lib/reply.js:204:7)
at /repo/node_modules/fastify/lib/wrapThenable.js:25:15
Possibly related:
https://github.com/fastify/fast-json-stringify/issues/218
https://github.com/fastify/fast-json-stringify/pull/84
Steps to Reproduce
export default async (app: FastifyInstance) => {
app.route({
method: 'GET',
url: '/test',
schema: {
response: {
200: {
type: 'object',
properties: {
status: { type: 'string' },
message: { type: 'string' },
testArray: {
type: 'array',
items: { type: 'string' }
}
}
}
}
},
handler: async () => {
return {
status: 'ok',
message: 'This is a test route',
testArray: ['test1', 'test2', 'test3', undefined]
}
}
})
}
Expected Behavior
It seems that asString will default the input to an empty string if its null.
I can confirm this behavior by sending ['test1', 'test2', 'test3', null] instead. No error is thrown, and my response looks like the following:
{
"status": "ok",
"message": "This is a test route",
"testArray": [
"test1",
"test2",
"test3",
""
]
}
I'm thinking that asString should check for undefined as well. However I understand that this may technically be incorrect because my response schema defines an array of strings, not Array<string | undefined>.
- 主要言語
- JavaScript
- スター
- 3.7k
- フォーク
- 245
- 平均マージ
- 3日 5時間
- マージ済み PR(30日)
- 16
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
fastify/fast-json-stringify のほかの issue
-
benchmark question
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
fastify/fast-json-stringify#782 · コメント 15 件 ·
メンテナーはふだん 2 日以内に返信
-
allOf Fails to Handle Array of if/then as Chained else Conditions対応中かも @junaidkhan80121 が 18 日前に担当しました。 オープンbug
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
fastify/fast-json-stringify#778 · コメント 5 件 ·
メンテナーはふだん 2 日以内に返信
-
emit CJS/ESM syntax in standalone mode based on AJV code options対応中かも @jaideeppyne が 101 日前に担当しました。 オープンfeature request
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
fastify/fast-json-stringify#679 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
feature request
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
fastify/fast-json-stringify#627 · コメント 4 件 · リアクション 3 件 ·
メンテナーはふだん 2 日以内に返信
-
Support TypedArrays対応中かも @junaidkhan80121 が 22 日前に担当しました。 オープンfeature request
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
fastify/fast-json-stringify#626 · コメント 1 件 · リアクション 4 件 ·
メンテナーはふだん 2 日以内に返信
fastify/fast-json-stringify の issue をすべて見る
似ている issue
-
FEATURE REQUEST
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
linuxmint/cinnamon-spices-applets#9356 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
needs-triage Platform(Default)
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 63/100
メンテナーはふだん 1 日以内に返信