Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,16 @@
raw: Buffer | string,
opts: CoTOptions = {}
): CoT {
const parsed = xml2js(String(raw), { compact: true }) as Static<typeof JSONCoT>;
const str = String(raw);

let parsed: Static<typeof JSONCoT>;
try {
parsed = xml2js(str, { compact: true }) as Static<typeof JSONCoT>;
} catch (err) {
console.error(`Failed to parse CoT XML: ${str}`);
throw err;
}

normalizeBooleanAttributeValues(parsed);

const cot = new CoT(
Expand Down Expand Up @@ -197,7 +206,7 @@

// The spread operator is important to make sure the delete doesn't modify the underlying detail object
const detail = { ...cot.raw.event.detail };
const msg: any = {

Check warning on line 209 in lib/parser.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 209 in lib/parser.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
cotEvent: {
...cot.raw.event._attributes,
sendTime: new Date(cot.raw.event._attributes.time).getTime(),
Expand Down Expand Up @@ -244,15 +253,15 @@
const ProtoMessage = RootMessage.lookupType(`atakmap.commoncommo.protobuf.v${version}.TakMessage`)

// TODO Type this
const msg: any = ProtoMessage.decode(raw);

Check warning on line 256 in lib/parser.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 256 in lib/parser.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

if (!msg.cotEvent) throw new Err(400, null, 'No cotEvent Data');

const detail: Record<string, any> = {};

Check warning on line 260 in lib/parser.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 260 in lib/parser.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
const metadata: Record<string, unknown> = {};
for (const key in msg.cotEvent.detail) {
if (key === 'xmlDetail') {
const parsed: any = xml2js(`<detail>${msg.cotEvent.detail.xmlDetail}</detail>`, { compact: true });

Check warning on line 264 in lib/parser.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 264 in lib/parser.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
normalizeBooleanAttributeValues(parsed);
Object.assign(detail, parsed.detail);

Expand Down
34 changes: 17 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading