ScrapboxのWebSocketのエラーの書式を調べ
やること
方法
書きかけ
code:js
await (async () => {
const projectId = "5f2f02f3c4a48d00237e1534";
const pageId = "61b1a4ae186f8a001da9362c";
const userId = "5ef2bdebb60650001e1280f0";
const parentId = "5ef2bdebb60650001e1280f0";
const {
socketIO, wrap,
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();
})();
だがなぜtitleとtitleLcがないと警告がでたんだ?
多分DBからリソースを取得するところまでは進んだんだと思う
そのあと、リソースの検証で躓いた、といったところかな?
code: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)"
}
},
}
}
code:js
await (async () => {
const projectId = "5f2f02f3c4a48d00237e1534";
const pageId = "61b1a4ae186f8a001da9362c";
const {
socketIO, wrap,
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
code:ts
await request("socket.io-request", {
method: "room:join",
data: {
projectId: null,
pageId: null,
projectUpdatesStream: false,
}
});
code:json
{
"success": true,
"message": "leaved from projectRoom and pageRoom."
}
projectId: nullでpageIdを指定した場合
code: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の整合が取れない場合
code:ts
interface PageUpdateResponse {
data: {
commitId: string;
};
error: {
name: "NotFastForwardError";
message: "Not fast-forward";
};
}
同名のタイトルが存在したとき
changesに{title: string;}が含まれていたときのみ発生する可能性がある
code:ts
interface DuplicateTitleError {
name: "DuplicateTitleError";
message: string;
}
存在しない行を削除しようとしたとき
code:json
{
"name": "Error",
"message": "Your changes have been declined by the server. delete line_id 61cb989d1280f00000cfd719 does not exists"
}
deleteはlines: -2でも通った
userIdが不正なのかも知れない
code:json
{
"name": "Error",
"message": "commit.userId is not valid ID \"5ef2bdebb60650001e1280f\""
}
_updateの変更のlines.textに改行入りの文字列を入れると、インデントの描画がおかしくなる
先頭の空白がインデントではなく空白と認識されてしまう
freeze: falseにしても特にエラーはでないようだ