Skip to content

Commit

Permalink
Merge pull request #343 from ethereum/content-not-found-errors
Browse files Browse the repository at this point in the history
Add `ContentNotFoundError`
  • Loading branch information
acolytec3 authored Oct 4, 2024
2 parents 380dc84 + fedc122 commit 845f0e6
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 11 deletions.
16 changes: 15 additions & 1 deletion jsonrpc/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ contentFiles.forEach(file => {
};
});

let errors = {};
let errorBase = "src/errors/"
let errorFiles = fs.readdirSync(errorBase)
errorFiles.forEach(file => {
console.log(file);
let raw = fs.readFileSync(errorBase + file);
let parsed = JSON.parse(raw);
errors = {
...errors,
...parsed,
};
});

let spec = await parseOpenRPCDocument({
openrpc: "1.2.4",
info: {
Expand All @@ -57,7 +70,8 @@ let spec = await parseOpenRPCDocument({
methods: methods,
components: {
contentDescriptors: content,
schemas: schemas
schemas: schemas,
errors: errors
}
},
{dereference: false})
Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/scripts/debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

set -o xtrace
curl -s http://localhost:8545 -H 'Content-Type: application/json' -d '{"method":"'$1'","id":1,"jsonrpc":"2.0", "params":['$2']}' | jq '.["result"]' > data.json 2>&1
cat openrpc.json | jq '.["methods"][] | select(.name == "'$1'") | .["result"]["schema"]' > schema.json
cat openrpc.json | jq '.["methods"][] | select(.name == "'$1'") | .["result"]["schema"]["errors"]' > schema.json
ajv validate -s schema.json -d data.json
# rm schema.json data.json
2 changes: 1 addition & 1 deletion jsonrpc/src/content/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
},
"LocalContentResult": {
"name": "LocalContentResult",
"description": "Returns the hex encoded content value. If the content is not available, returns \"0x\"",
"description": "Returns the hex encoded content value.",
"schema": {
"$ref": "#/components/schemas/hexString"
}
Expand Down
13 changes: 13 additions & 0 deletions jsonrpc/src/errors/errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"ContentNotFoundError": {
"code": -39001,
"message": "content not found"
},
"ContentNotFoundErrorWithTrace": {
"code": -39002,
"message": "content not found",
"data": {
"$ref": "#/components/schemas/traceResultObject"
}
}
}
15 changes: 12 additions & 3 deletions jsonrpc/src/methods/beacon.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@
],
"result": {
"$ref": "#/components/contentDescriptors/RecursiveFindContentResult"
}
},
"errors":[{
"$ref": "#/components/errors/ContentNotFoundError"
}]
},
{
"name": "portal_beaconTraceRecursiveFindContent",
Expand All @@ -154,7 +157,10 @@
],
"result": {
"$ref": "#/components/contentDescriptors/TraceRecursiveFindContentResult"
}
},
"errors":[{
"$ref": "#/components/errors/ContentNotFoundErrorWithTrace"
}]
},
{
"name": "portal_beaconStore",
Expand All @@ -181,7 +187,10 @@
],
"result": {
"$ref": "#/components/contentDescriptors/LocalContentResult"
}
},
"errors":[{
"$ref": "#/components/errors/ContentNotFoundError"
}]
},
{
"name": "portal_beaconGossip",
Expand Down
15 changes: 12 additions & 3 deletions jsonrpc/src/methods/history.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@
],
"result": {
"$ref": "#/components/contentDescriptors/RecursiveFindContentResult"
}
},
"errors":[{
"$ref": "#/components/errors/ContentNotFoundError"
}]
},
{
"name": "portal_historyTraceRecursiveFindContent",
Expand All @@ -146,7 +149,10 @@
],
"result": {
"$ref": "#/components/contentDescriptors/TraceRecursiveFindContentResult"
}
},
"errors":[{
"$ref": "#/components/errors/ContentNotFoundErrorWithTrace"
}]
},
{
"name": "portal_historyStore",
Expand All @@ -173,7 +179,10 @@
],
"result": {
"$ref": "#/components/contentDescriptors/LocalContentResult"
}
},
"errors":[{
"$ref": "#/components/errors/ContentNotFoundError"
}]
},
{
"name": "portal_historyGossip",
Expand Down
25 changes: 23 additions & 2 deletions jsonrpc/src/methods/state.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,25 @@
],
"result": {
"$ref": "#/components/contentDescriptors/RecursiveFindContentResult"
}
},
"errors":[{
"$ref": "#/components/errors/ContentNotFoundError"
}]
},
{
"name": "portal_stateTraceRecursiveFindContent",
"summary": "Look up a target content key in the network and get tracing data",
"params": [
{
"$ref": "#/components/contentDescriptors/ContentKey"
}
],
"result": {
"$ref": "#/components/contentDescriptors/TraceRecursiveFindContentResult"
},
"errors":[{
"$ref": "#/components/errors/ContentNotFoundErrorWithTrace"
}]
},
{
"name": "portal_stateStore",
Expand All @@ -161,7 +179,10 @@
],
"result": {
"$ref": "#/components/contentDescriptors/LocalContentResult"
}
},
"errors":[{
"$ref": "#/components/errors/ContentNotFoundError"
}]
},
{
"name": "portal_stateGossip",
Expand Down

0 comments on commit 845f0e6

Please sign in to comment.