Skip to content

Commit 5a220ab

Browse files
committed
fix(generate): handle invalid signal name for metadata
1 parent 7798b54 commit 5a220ab

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

internal/generate/compile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ func (c *compiler) addMetadata() {
189189
sig, ok := c.db.Signal(def.MessageID.ToCAN(), string(def.SignalName))
190190
if !ok {
191191
c.addWarning(&compileError{def: def, reason: "no declared signal"})
192+
continue
192193
}
193194
if def.AttributeName == "GenSigStartValue" {
194195
sig.DefaultValue = int(def.IntValue)

internal/generate/compile_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,17 @@ func Test_CopyFrom_PreservesOutOfRangeValues(t *testing.T) {
403403
t.Errorf("Expected frames of messages to be identical (%v != %v)", m2.Frame(), original.Frame())
404404
}
405405
}
406+
407+
func TestCompile_MetadataInvalidSignalReference(t *testing.T) {
408+
finish := runTestInDir(t, "../..")
409+
defer finish()
410+
const exampleDBCFile = "testdata/dbc-invalid/example/example_metadata_invalid_signal_reference.dbc"
411+
input, err := os.ReadFile(exampleDBCFile)
412+
assert.NilError(t, err)
413+
result, err := Compile(exampleDBCFile, input)
414+
if err != nil {
415+
t.Fatal(err)
416+
}
417+
// We expect one warning for incorrect signal length in declaration of float32 signal
418+
assert.Equal(t, len(result.Warnings), 1)
419+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
VERSION ""
2+
3+
NS_ :
4+
5+
BS_:
6+
7+
BU_: DBG IO
8+
9+
BO_ 42 AMessage: 8 Vector__XXX
10+
SG_ ASignal : 7|16@0- (1,0) [-32768|32767] "%" Vector__XXX
11+
12+
BA_DEF_ SG_ "GenSigStartValue" FLOAT -3.4E+038 3.4E+038;
13+
BA_DEF_DEF_ "GenSigStartValue" 0;
14+
BA_ "GenSigStartValue" SG_ 42 AnotherSignalName 0;

0 commit comments

Comments
 (0)