-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added better error information for unicity verifiers
- Loading branch information
Showing
4 changed files
with
31 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,30 @@ | ||
import { uniq } from "lodash"; | ||
import { groupBy, keys, pickBy } from "lodash"; | ||
import { ContractNode } from "../../models/nodes"; | ||
import { VerificationError } from "../verification-error"; | ||
|
||
export function verifyUniqueEndpointNames( | ||
contract: ContractNode | ||
): VerificationError[] { | ||
const errors: VerificationError[] = []; | ||
const endpointNames = contract.endpoints.map( | ||
|
||
const endpointsByName = groupBy( | ||
contract.endpoints, | ||
endpoint => endpoint.value.name.value | ||
); | ||
if (uniq(endpointNames).length !== endpointNames.length) { | ||
|
||
const duplicatedEndpoints = pickBy( | ||
endpointsByName, | ||
endpointCollection => endpointCollection.length > 1 | ||
); | ||
|
||
keys(duplicatedEndpoints).forEach(endpointName => { | ||
const firstEndpointWithName = duplicatedEndpoints[endpointName][0]; | ||
errors.push({ | ||
message: "endpoints must have unique names", | ||
// TODO: use a duplicated endpoint location | ||
location: contract.api.location, | ||
line: contract.api.line | ||
message: `endpoints must have unique names: ${endpointName}`, | ||
location: firstEndpointWithName.value.name.location, | ||
line: firstEndpointWithName.value.name.line | ||
}); | ||
} | ||
}); | ||
|
||
return errors; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
import { uniq } from "lodash"; | ||
import { groupBy, keys, pickBy } from "lodash"; | ||
import { ContractNode } from "../../models/nodes"; | ||
import { VerificationError } from "../verification-error"; | ||
|
||
export function verifyUniqueTypeNames( | ||
contract: ContractNode | ||
): VerificationError[] { | ||
const errors: VerificationError[] = []; | ||
const typeNames = contract.types.map(type => type.name); | ||
if (uniq(typeNames).length !== typeNames.length) { | ||
|
||
const typesByName = groupBy(contract.types, type => type.name); | ||
const duplicatedTypes = pickBy( | ||
typesByName, | ||
typeCollection => typeCollection.length > 1 | ||
); | ||
|
||
keys(duplicatedTypes).forEach(typeName => { | ||
errors.push({ | ||
message: "types must have unique names", | ||
message: `types must have unique names: ${typeName}`, | ||
// TODO: use a duplicated type location | ||
location: contract.api.location, | ||
line: contract.api.line | ||
}); | ||
} | ||
}); | ||
|
||
return errors; | ||
} |