Skip to content

Commit e9bfcdc

Browse files
authored
Fix backticks in message definitions, throw better error on missing dependencies. (#205)
* Message gen: escape backticks in comments Until now, backticks ("`") in comments in message definitions will lead to an exception when the generated message is loaded, because the generated JS code is syntactically invalid. * Message generation: indicate name of missing dependencies Previously, if a custom message definition referred to another package that was missing, the error was not giving any clues as to where the problem occurred, i.e., which packages are involved. This change fixes that, making it much easy to debug broken dependencies.
1 parent eacfffc commit e9bfcdc

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/utils/messageGeneration/MessageLoader.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ class MessageManager {
394394
const depIndex = dependencyChain.indexOf(depName);
395395
if (depIndex === -1) {
396396
// this dependency is not yet in the list anywhere
397+
if (!packageCache[depName]) {
398+
throw Error(`Missing dependency ${depName}, required by ${packageName}`);
399+
}
397400
const insertionIndex = this._recurseDependencyChain(dependencyChain, depName);
398401
if (insertionIndex > maxInsertionIndex) {
399402
maxInsertionIndex = insertionIndex;

src/utils/messageGeneration/MessageSpec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,17 @@ class RosMsgSpec {
264264

265265
const deps = this.getFullDependencies();
266266
const sep = '='.repeat(80);
267-
w.write(this.fileContents.trim())
267+
268+
// escape backticks in string
269+
const sanitize = (string) => string.trim().replace(/`/g, '\\`');
270+
271+
w.write(sanitize(this.fileContents))
268272
.newline();
269273

270274
deps.forEach((dep) => {
271275
w.write(sep)
272276
.write(`MSG: ${dep.getFullMessageName()}`)
273-
.write(dep.fileContents.trim())
277+
.write(sanitize(dep.fileContents))
274278
.newline();
275279
});
276280

0 commit comments

Comments
 (0)