Skip to content

Commit

Permalink
Updating error link references (tywalch#198)
Browse files Browse the repository at this point in the history
* Updates error detail url references

* Remove existing table documentation until its back working

* Fixes issue that resulted in provided undefined values from becoming involuntarily set via updates
  • Loading branch information
tywalch authored Dec 19, 2022
1 parent 4ebdc4c commit 3fa2460
Show file tree
Hide file tree
Showing 29 changed files with 266 additions and 196 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@ dist
# TernJS port file
.tern-port

playground/bundle.js
playground/bundle.js
test/debug.ts
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ All notable changes to this project will be documented in this file. Breaking ch
### Fixed
- Issue #182: Addressed inconsistency with `remove` and `delete` functionality between `update` and `patch` methods.

## [2.3.4] - 2022-11-28
## [2.3.4] - 2022-12-17
### Milestone
- First code contribution by user @NoahDavey (via [PR-197](https://github.com/tywalch/electrodb/pull/197)). Fixes boolean evaluation during upsert
- First code contribution by user @NoahDavey (via [PR-197](https://github.com/tywalch/electrodb/pull/197)). Fixes boolean evaluation during upsert

## [2.3.5] - 2022-12-18
### Fixed
- Fixes issue that resulted in provided undefined values from becoming involuntarily set via updates
- Updated documentation links in error message to direct traffic to https://electrodb.dev
2 changes: 1 addition & 1 deletion src/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class Entity {
return Promise.reject(err);
} else {
if (err.__isAWSError) {
stackTrace.message = new e.ElectroError(e.ErrorCodes.AWSError, err.message).message;
stackTrace.message = new e.ElectroError(e.ErrorCodes.AWSError, `Error thrown by DynamoDB client: "${err.message}"`).message;
return Promise.reject(stackTrace);
} else if (err.isElectroError) {
return Promise.reject(err);
Expand Down
2 changes: 1 addition & 1 deletion src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

function getHelpLink(section) {
section = section || "unknown-error-5001";
return `https://github.com/tywalch/electrodb#${section}`;
return `https://electrodb.dev/en/reference/errors/#${section}`;
}

const ErrorCode = Symbol("error-code");
Expand Down
3 changes: 3 additions & 0 deletions src/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ class AttributeOperationProxy {

fromObject(operation, record) {
for (let path of Object.keys(record)) {
if (record[path] === undefined) {
continue;
}
const value = record[path];
const parts = u.parseJSONPath(path);
let attribute = this.attributes;
Expand Down
4 changes: 2 additions & 2 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class Attribute {

_makeApplyFixings({ prefix = "", postfix = "", casing= KeyCasing.none } = {}) {
return (value) => {
if ([AttributeTypes.string, AttributeTypes.enum].includes(this.type)) {
if ([AttributeTypes.string, AttributeTypes.enum].includes(this.type) && value !== undefined) {
value = `${prefix}${value}${postfix}`;
}

Expand Down Expand Up @@ -458,7 +458,7 @@ class Attribute {
let reason = [];
switch (this.type) {
case AttributeTypes.enum:
case AttributeTypes.enumSet:
// case AttributeTypes.enumSet:
// isTyped = this.enumArray.every(enumValue => {
// const val = Array.isArray(value) ? value : [value];
// return val.includes(enumValue);
Expand Down
2 changes: 1 addition & 1 deletion src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class Service {
default:
/** start beta/v1 condition **/
if (modelVersion !== this._modelVersion) {
throw new e.ElectroError(e.ErrorCodes.InvalidJoin, "Invalid instance: Valid instances to join include Models and Entity instances. Additionally, all models must be in the same format (v1 vs beta). Review https://github.com/tywalch/electrodb#version-v1-migration for more detail.");
throw new e.ElectroError(e.ErrorCodes.InvalidJoin, "Invalid instance: Valid instances to join include Models and Entity instances.");
} else if (modelVersion === ModelVersions.beta) {
instance = applyBetaModelOverrides(instance, this._modelOverrides);
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/connected.batch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ describe("BatchGet", () => {
});
});
it("Should throw on invalid get composite attributes", () => {
expect(() => MallStores.get([record1, record2, record3, {}]).params()).to.throw('Incomplete or invalid key composite attributes supplied. Missing properties: "sector" - For more detail on this error reference: https://github.com/tywalch/electrodb#incomplete-composite-attributes');
expect(() => MallStores.get([record1, record2, record3, {}]).params()).to.throw('Incomplete or invalid key composite attributes supplied. Missing properties: "sector" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#incomplete-composite-attributes');
});
it("Should create params", () => {
let params = MallStores.get([record1, record2, record3]).params();
Expand Down
30 changes: 15 additions & 15 deletions test/connected.crud.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ for (const [clientVersion, client] of [[c.DocumentClientVersions.v2, v2Client],
try {
recordTwo = await MallStores.create(record).go().then(res => res.data);
} catch(err) {
expect(err.message).to.be.equal("The conditional request failed - For more detail on this error reference: https://github.com/tywalch/electrodb#aws-error");
expect(err.message).to.be.equal('Error thrown by DynamoDB client: "The conditional request failed" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#aws-error');
}
expect(recordTwo).to.be.null;
});
Expand Down Expand Up @@ -361,7 +361,7 @@ for (const [clientVersion, client] of [[c.DocumentClientVersions.v2, v2Client],
try {
patchResultsTwo = await MallStores.patch({sector, id: `${id}-2`}).set({rent: "200.00"}).go().then(res => res.data);
} catch(err) {
expect(err.message).to.be.equal("The conditional request failed - For more detail on this error reference: https://github.com/tywalch/electrodb#aws-error");
expect(err.message).to.be.equal('Error thrown by DynamoDB client: "The conditional request failed" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#aws-error');
}
expect(patchResultsTwo).to.be.null
});
Expand All @@ -384,8 +384,8 @@ for (const [clientVersion, client] of [[c.DocumentClientVersions.v2, v2Client],
expect(electroSuccess).to.be.false;
expect(electroErr.stack.split(/\r?\n/)[1].includes("aws-sdk")).to.be.false;
expect([
"Requested resource not found - For more detail on this error reference: https://github.com/tywalch/electrodb#aws-error",
"Cannot do operations on a non-existent table - For more detail on this error reference: https://github.com/tywalch/electrodb#aws-error"
'Error thrown by DynamoDB client: "Requested resource not found" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#aws-error',
'Error thrown by DynamoDB client: "Cannot do operations on a non-existent table" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#aws-error'
].includes(electroErr.message)).to.be.true;
expect(originalSuccess).to.be.false;
expect(originalErr.stack.split(/\r?\n/)[1].includes("aws-sdk")).to.be.true;
Expand Down Expand Up @@ -668,7 +668,7 @@ for (const [clientVersion, client] of [[c.DocumentClientVersions.v2, v2Client],
try {
recordTwo = await MallStores.create(record).go();
} catch(err) {
expect(err.message).to.be.equal("The conditional request failed - For more detail on this error reference: https://github.com/tywalch/electrodb#aws-error");
expect(err.message).to.be.equal('Error thrown by DynamoDB client: "The conditional request failed" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#aws-error');
}
expect(recordTwo).to.be.null
});
Expand Down Expand Up @@ -701,7 +701,7 @@ for (const [clientVersion, client] of [[c.DocumentClientVersions.v2, v2Client],
try {
patchResultsTwo = await MallStores.patch({sector, id: `${id}-2`}).set({rent: "200.00"}).go().then(res => res.data);
} catch(err) {
expect(err.message).to.be.equal("The conditional request failed - For more detail on this error reference: https://github.com/tywalch/electrodb#aws-error");
expect(err.message).to.be.equal('Error thrown by DynamoDB client: "The conditional request failed" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#aws-error');
}
expect(patchResultsTwo).to.be.null
});
Expand All @@ -723,8 +723,8 @@ for (const [clientVersion, client] of [[c.DocumentClientVersions.v2, v2Client],
expect(electroSuccess).to.be.false;
expect(electroErr.stack.split(/\r?\n/)[1].includes("aws-sdk")).to.be.false;
expect([
"Requested resource not found - For more detail on this error reference: https://github.com/tywalch/electrodb#aws-error",
"Cannot do operations on a non-existent table - For more detail on this error reference: https://github.com/tywalch/electrodb#aws-error"
'Error thrown by DynamoDB client: "Requested resource not found" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#aws-error',
'Error thrown by DynamoDB client: "Cannot do operations on a non-existent table" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#aws-error'
].includes(electroErr.message)).to.be.true;
expect(originalSuccess).to.be.false;
expect(originalErr.stack.split(/\r?\n/)[1].includes("aws-sdk")).to.be.true;
Expand Down Expand Up @@ -1701,7 +1701,7 @@ for (const [clientVersion, client] of [[c.DocumentClientVersions.v2, v2Client],
.then((res) => [true, res])
.catch(err => [false, err])
expect(success).to.be.false;
expect(result.message).to.equal(`Attribute "updatedAt" is Read-Only and cannot be updated - For more detail on this error reference: https://github.com/tywalch/electrodb#invalid-attribute`);
expect(result.message).to.equal(`Attribute "updatedAt" is Read-Only and cannot be updated - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#invalid-attribute`);
});
});
describe("Setter Triggers", () => {
Expand Down Expand Up @@ -3103,7 +3103,7 @@ for (const [clientVersion, client] of [[c.DocumentClientVersions.v2, v2Client],
}
}

expect(() => new Entity(schema)).to.throw(`Attribute Validation Error. Attributes may only "watch" other attributes also watch attributes. The following attributes are defined with ineligible attributes to watch: "prop3"->"prop2", "prop5"->"prop2", "prop4"->"prop3", "prop5"->"prop3", "prop5"->"prop4". - For more detail on this error reference: https://github.com/tywalch/electrodb#invalid-attribute-watch-definition`);
expect(() => new Entity(schema)).to.throw(`Attribute Validation Error. Attributes may only "watch" other attributes also watch attributes. The following attributes are defined with ineligible attributes to watch: "prop3"->"prop2", "prop5"->"prop2", "prop4"->"prop3", "prop5"->"prop3", "prop5"->"prop4". - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#invalid-attribute-watch-definition`);
});
it("Should not allow a watcher to watch an unknown property", () => {
let schema = {
Expand Down Expand Up @@ -3135,7 +3135,7 @@ for (const [clientVersion, client] of [[c.DocumentClientVersions.v2, v2Client],
}
}

expect(() => new Entity(schema)).to.throw(`Attribute Validation Error. The following attributes are defined to "watch" invalid/unknown attributes: "prop3"->"unknown". - For more detail on this error reference: https://github.com/tywalch/electrodb#invalid-attribute-watch-definition`);
expect(() => new Entity(schema)).to.throw(`Attribute Validation Error. The following attributes are defined to "watch" invalid/unknown attributes: "prop3"->"unknown". - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#invalid-attribute-watch-definition`);
});
});
describe("Query Options", () => {
Expand Down Expand Up @@ -3502,7 +3502,7 @@ for (const [clientVersion, client] of [[c.DocumentClientVersions.v2, v2Client],
throw null;
} catch(err) {
expect(err).to.not.be.null;
expect(err.message).to.equal(`Attribute "prop2" is Read-Only and cannot be updated - For more detail on this error reference: https://github.com/tywalch/electrodb#invalid-attribute`);
expect(err.message).to.equal(`Attribute "prop2" is Read-Only and cannot be updated - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#invalid-attribute`);
}
});

Expand All @@ -3515,7 +3515,7 @@ for (const [clientVersion, client] of [[c.DocumentClientVersions.v2, v2Client],
throw null;
} catch(err) {
expect(err).to.not.be.null;
expect(err.message).to.equal(`Attribute "prop2" is Read-Only and cannot be updated - For more detail on this error reference: https://github.com/tywalch/electrodb#invalid-attribute`);
expect(err.message).to.equal(`Attribute "prop2" is Read-Only and cannot be updated - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#invalid-attribute`);
}
});

Expand All @@ -3527,7 +3527,7 @@ for (const [clientVersion, client] of [[c.DocumentClientVersions.v2, v2Client],
throw null;
} catch(err) {
expect(err).to.not.be.null;
expect(err.message).to.equal(`Incomplete composite attributes: Without the composite attributes "prop7", "prop8" the following access patterns cannot be updated: "index3" - For more detail on this error reference: https://github.com/tywalch/electrodb#incomplete-composite-attributes`);
expect(err.message).to.equal(`Incomplete composite attributes: Without the composite attributes "prop7", "prop8" the following access patterns cannot be updated: "index3" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#incomplete-composite-attributes`);
}
});

Expand All @@ -3539,7 +3539,7 @@ for (const [clientVersion, client] of [[c.DocumentClientVersions.v2, v2Client],
throw null;
} catch(err) {
expect(err).to.not.be.null;
expect(err.message).to.equal(`Incomplete composite attributes: Without the composite attributes "prop7", "prop8" the following access patterns cannot be updated: "index3" - For more detail on this error reference: https://github.com/tywalch/electrodb#incomplete-composite-attributes`);
expect(err.message).to.equal(`Incomplete composite attributes: Without the composite attributes "prop7", "prop8" the following access patterns cannot be updated: "index3" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#incomplete-composite-attributes`);
}
});

Expand Down
12 changes: 6 additions & 6 deletions test/connected.page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ describe("Page", () => {
// page: {task: "1234", project: undefined}
// },
// output: {
// error: 'Incomplete or invalid key composite attributes supplied. Missing properties: "project" - For more detail on this error reference: https://github.com/tywalch/electrodb#incomplete-composite-attributes'
// error: 'Incomplete or invalid key composite attributes supplied. Missing properties: "project" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#incomplete-composite-attributes'
// },
// }, {
// type: "query",
Expand All @@ -418,15 +418,15 @@ describe("Page", () => {
// page: {task: "1234", project: "anc"}
// },
// output: {
// error: 'Incomplete or invalid key composite attributes supplied. Missing properties: "employee" - For more detail on this error reference: https://github.com/tywalch/electrodb#incomplete-composite-attributes'
// error: 'Incomplete or invalid key composite attributes supplied. Missing properties: "employee" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#incomplete-composite-attributes'
// },
// }, {
// type: "scan",
// input: {
// page: {task: "1234", project: undefined}
// },
// output: {
// error: 'Incomplete or invalid key composite attributes supplied. Missing properties: "project", "employee" - For more detail on this error reference: https://github.com/tywalch/electrodb#incomplete-composite-attributes'
// error: 'Incomplete or invalid key composite attributes supplied. Missing properties: "project", "employee" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#incomplete-composite-attributes'
// },
// }
// ];
Expand Down Expand Up @@ -475,7 +475,7 @@ describe("Page", () => {
.then(results => ({success: true, results}))
.catch(results => ({success: false, results}));
expect(success).to.be.false;
expect(results.message).to.be.equal("No client defined on model - For more detail on this error reference: https://github.com/tywalch/electrodb#no-client-defined-on-model")
expect(results.message).to.be.equal("No client defined on model - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#no-client-defined-on-model")
});

describe("query pagination", () => {
Expand Down Expand Up @@ -987,7 +987,7 @@ describe("Page", () => {
it("should throw if 'pages' option is less than one or not a valid number", async () => {
const employee = "employee";
const project = "project";
const message = "Query option 'pages' must be of type 'number' and greater than zero or the string value 'all' - For more detail on this error reference: https://github.com/tywalch/electrodb#invalid-pages-option";
const message = "Query option 'pages' must be of type 'number' and greater than zero or the string value 'all' - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#invalid-pages-option";
const result1 = await service.collections.assignments({employee}).go({pages: -1})
.then(() => ({success: true}))
.catch(err => ({success: false, message: err.message}));
Expand Down Expand Up @@ -1028,7 +1028,7 @@ describe("Page", () => {
it("should throw if 'limit' option is less than one or not a valid number", async () => {
const employee = "employee";
const project = "project";
const message = "Query option 'limit' must be of type 'number' and greater than zero. - For more detail on this error reference: https://github.com/tywalch/electrodb#invalid-limit-option";
const message = "Query option 'limit' must be of type 'number' and greater than zero. - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#invalid-limit-option";
const result1 = await service.collections.assignments({employee}).go({limit: -1})
.then(() => ({success: true}))
.catch(err => ({success: false, message: err.message}));
Expand Down
Loading

0 comments on commit 3fa2460

Please sign in to comment.