Skip to content

Commit

Permalink
fix: throw when .proto is empty (#81)
Browse files Browse the repository at this point in the history
Refuse to compile an empty .proto file
  • Loading branch information
achingbrain authored Jan 31, 2023
1 parent a34a908 commit ed392cb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/protons/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ export async function generate (source: string, flags: Flags): Promise<void> {

const def = JSON.parse(json)

for (const [className, classDef] of Object.entries<any>(def.nested)) {
for (const [className, classDef] of Object.entries<any>(def.nested ?? {})) {
for (const [fieldName, fieldDef] of Object.entries<any>(classDef.fields ?? {})) {
if (fieldDef.keyType == null) {
continue
Expand Down
Empty file.
5 changes: 5 additions & 0 deletions packages/protons/test/unsupported.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ describe('unsupported', () => {
await expect(generate('test/fixtures/proto2.proto', {})).to.eventually.be.rejected
.with.property('message').that.contain('"required" fields are not allowed in proto3')
})

it('should refuse to generate source from empty definition', async () => {
await expect(generate('test/fixtures/empty.proto', {})).to.eventually.be.rejected
.with.property('message').that.contain('No top-level messages found in protobuf')
})
})

0 comments on commit ed392cb

Please sign in to comment.