generated at
ScrapboxのWebSocketのエラーの書式を調べ
やること
ScrapboxのWebSocketで投げられるerror objectの書式を調べる

方法
scrapbox-userscript-websocketを使って、エラーを引き起こすデータを送信する
書きかけ
js
await (async () => { const projectId = "5f2f02f3c4a48d00237e1534"; const pageId = "61b1a4ae186f8a001da9362c"; const userId = "5ef2bdebb60650001e1280f0"; const parentId = "5ef2bdebb60650001e1280f0"; const { socketIO, wrap, } = await import("https://scrapbox.io/api/code/takker/scrapbox-userscript-websocket/mod.js"); const io = await socketIO(); const { request } = wrap(io); console.info( await request("socket.io-request", { method: "commit", data: { kind: "page", projectId, parentId, pageId, userId, changes: [], cursor: null, freeze: true, }, }) ); io.disconnect(); })();
どうやらschematypeを使って型チェックを行っているようだ
だがなぜ title titleLc がないと警告がでたんだ?
多分DBからリソースを取得するところまでは進んだんだと思う
そのあと、リソースの検証で躓いた、といったところかな?
ts
const validationError = { name: "ValidationError", message: "page validation failed: title: Path `title` is required., titleLc: Path `titleLc` is required.", _message: "page validation failed", errors: { title: { properties: { message: "Path `title` is required.", type: "required", path: "title", value: "" }, kind: "required", path: "title", value: "", name: "ValidatorError", message: "Path `title` is required.", stack: `ValidatorError: Path \`title\` is required. at validate (/app/node_modules/mongoose/lib/schematype.js:1270:13) at /app/node_modules/mongoose/lib/schematype.js:1253:7 at Array.forEach (<anonymous>) at SchemaString.SchemaType.doValidate (/app/node_modules/mongoose/lib/schematype.js:1198:14) at /app/node_modules/mongoose/lib/document.js:2567:18 at processTicksAndRejections (node:internal/process/task_queues:78:11)` }, titleLc: { "properties": { "message": "Path `titleLc` is required.", "type": "required", "path": "titleLc", "value": "" }, "kind": "required", "path": "titleLc", "value": "", "name": "ValidatorError", "message": "Path `titleLc` is required.", "stack": "ValidatorError: Path `titleLc` is required.\n at validate (/app/node_modules/mongoose/lib/schematype.js:1270:13)\n at /app/node_modules/mongoose/lib/schematype.js:1253:7\n at Array.forEach (<anonymous>)\n at SchemaString.SchemaType.doValidate (/app/node_modules/mongoose/lib/schematype.js:1198:14)\n at /app/node_modules/mongoose/lib/document.js:2567:18\n at processTicksAndRejections (node:internal/process/task_queues:78:11)" } }, } }
js
await (async () => { const projectId = "5f2f02f3c4a48d00237e1534"; const pageId = "61b1a4ae186f8a001da9362c"; const { socketIO, wrap, } = await import("https://scrapbox.io/api/code/takker/scrapbox-userscript-websocket/mod.js"); const io = await socketIO(); const { request } = wrap(io); console.info( await request("socket.io-request", { method: "room:join", data: { projectId, pageId, projectUpdatesStream: false, } }) ); io.disconnect(); })();

結果
socket.io-request , room:join
ts
await request("socket.io-request", { method: "room:join", data: { projectId: null, pageId: null, projectUpdatesStream: false, } });
json
{ "success": true, "message": "leaved from projectRoom and pageRoom." }
projectId: null pageId を指定した場合
json
{ "error": { "errors": [ { "name": "Error", "message": "cannot join to pageRoom without projectId.", "stack": "Error: cannot join to pageRoom without projectId.\n at reject (/app/build/server/sockets/join-room.js:1:948)\n at /app/build/server/sockets/join-room.js:1:1074\n at next (/app/node_modules/combine-middlewares/lib/index.js:27:28)\n at /app/node_modules/combine-middlewares/lib/index.js:29:12\n at Socket.<anonymous> (/app/node_modules/socket.io-request/lib/main.js:85:9)\n at Socket.emit (node:events:402:35)\n at Socket.emitUntyped (/app/node_modules/socket.io/dist/typed-events.js:69:22)\n at /app/node_modules/socket.io/dist/socket.js:428:39\n at processTicksAndRejections (node:internal/process/task_queues:78:11)" } ] } }
projectUpdatesStream を削ったりいい加減な値を入れてもエラーはでない
socket.io-request , commit
commitの整合が取れない場合
ts
interface PageUpdateResponse { data: { commitId: string; }; error: { name: "NotFastForwardError"; message: "Not fast-forward"; }; }
同名のタイトルが存在したとき
changes {title: string;} が含まれていたときのみ発生する可能性がある
ts
interface DuplicateTitleError { name: "DuplicateTitleError"; message: string; }
存在しない行を削除しようとしたとき
json
{ "name": "Error", "message": "Your changes have been declined by the server. delete line_id 61cb989d1280f00000cfd719 does not exists" }
deleteは lines: -2 でも通った
userIdが不正なのかも知れない
json
{ "name": "Error", "message": "commit.userId is not valid ID \"5ef2bdebb60650001e1280f\"" }
_update の変更の lines.text に改行入りの文字列を入れると、インデントの描画がおかしくなる
先頭の空白がインデントではなく空白と認識されてしまう
freeze: false にしても特にエラーはでないようだ

#2022-02-11 16:40:44 リンク貼った
#2021-12-29 07:19:30