Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved error messages #196

Merged
merged 2 commits into from
Jan 15, 2024
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,5 @@ $RECYCLE.BIN/
!.vscode/extensions.json
/src/SharpBrick.PoweredUp.BlueGigaBLE/.editorconfig
/examples/SharpBrick.PoweredUp.Examples/Properties/launchSettings.json
src/SharpBrick.PoweredUp.Cli/Properties/launchSettings.json
/src/SharpBrick.PoweredUp.Cli/Properties/launchSettings.json
/src/SharpBrick.PoweredUp.Cli/poweredup.json
2 changes: 1 addition & 1 deletion src/SharpBrick.PoweredUp/Devices/Current.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ public IEnumerable<byte[]> GetStaticPortInfoMessages(Version softwareVersion, Ve
08-00-44-3B-01-05-10-00
0A-00-44-3B-01-80-01-01-04-00
",
_ => throw new NotSupportedException(),
_ => throw BuildNotSupportedException(softwareVersion, hardwareVersion, systemType),
}).Trim().Split("\n").Select(s => BytesStringUtil.StringToData(s));
}
5 changes: 5 additions & 0 deletions src/SharpBrick.PoweredUp/Devices/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ protected void AssertIsVirtualPort()
}
}

protected NotSupportedException BuildNotSupportedException(Version softwareVersion, Version hardwareVersion, SystemType systemType)
{
return new NotSupportedException($"Device '{this.GetType().Name}' does not support Systemtype '{systemType}' on Hardware '{hardwareVersion}' and Software '{ softwareVersion }'");
}

#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
Expand Down
2 changes: 1 addition & 1 deletion src/SharpBrick.PoweredUp/Devices/RgbLight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,6 @@ public IEnumerable<byte[]> GetStaticPortInfoMessages(Version softwareVersion, Ve
08-00-44-32-01-05-00-10
0A-00-44-32-01-80-03-00-03-00
",
_ => throw new NotSupportedException(),
_ => throw BuildNotSupportedException(softwareVersion, hardwareVersion, systemType)
}).Trim().Split("\n").Select(s => BytesStringUtil.StringToData(s));
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,6 @@ public IEnumerable<byte[]> GetStaticPortInfoMessages(Version softwareVersion, Ve
08-00-44-63-02-05-00-10
0A-00-44-63-02-80-02-00-03-00
".Trim().Split("\n").Select(s => BytesStringUtil.StringToData(s)),
_ => throw new NotSupportedException("SharpBrick.PoweredUp currently does not support this version of the sensor."),
_ => throw BuildNotSupportedException(softwareVersion, hardwareVersion, systemType),
};
}
2 changes: 1 addition & 1 deletion src/SharpBrick.PoweredUp/Devices/Voltage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ public IEnumerable<byte[]> GetStaticPortInfoMessages(Version softwareVersion, Ve
08-00-44-3C-01-05-10-00
0A-00-44-3C-01-80-01-01-04-00
",
_ => throw new NotImplementedException(),
_ => throw BuildNotSupportedException(softwareVersion, hardwareVersion, systemType),
}).Trim().Split("\n").Select(s => BytesStringUtil.StringToData(s));
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public PortModeInfo PortMode(byte hubId, byte portId, byte modeIndex)

if (!(port.Modes.TryGetValue(modeIndex, out var result)))
{
throw new ArgumentException("modeIndex is null", nameof(modeIndex));
throw new ArgumentException($"Unknown modeIndex {modeIndex}, on portId {portId} for hubId {hubId}", nameof(modeIndex));
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion src/SharpBrick.PoweredUp/Protocol/LegoWirelessProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ await KnowledgeManager.ApplyDynamicProtocolKnowledge(new HubPropertyMessage<Syst
}, Knowledge, _deviceFactory);

await _kernel.ConnectAsync();

_logger.LogInformation("Connected to device, getting protocol information");
await _kernel.ReceiveBytesAsync(async data =>
{
try
Expand Down
Loading