Skip to content

Commit

Permalink
Remove all Logger. null warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
CartBlanche committed Oct 12, 2023
1 parent 63228f1 commit b845e00
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
7 changes: 5 additions & 2 deletions Source/v2/Meadow.Cli/Commands/Current/App/AppDeployCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,15 @@ protected override async ValueTask ExecuteCommand()

var targetDirectory = file.DirectoryName;

await AppManager.DeployApplication(_packageManager, connection, targetDirectory, true, false, Logger, CancellationToken);
if (Logger != null && !string.IsNullOrEmpty(targetDirectory))
{
await AppManager.DeployApplication(_packageManager, connection, targetDirectory, true, false, Logger, CancellationToken);
}

if (wasRuntimeEnabled)
{
// restore runtime state
Logger.LogInformation("Enabling runtime...");
Logger?.LogInformation("Enabling runtime...");

await connection.RuntimeEnable(CancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ protected override async ValueTask ExecuteCommand()

var data = await connection.Device.ReadFileString(MeadowFile, CancellationToken);

Logger.LogInformation(data);
Logger?.LogInformation(data);
}
}
28 changes: 14 additions & 14 deletions Source/v2/Meadow.Cli/Commands/Legacy/FlashOsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override async ValueTask ExecuteCommand()

if (Files == null)
{
Logger.LogInformation($"Writing all firmware for version '{package.Version}'...");
Logger?.LogInformation($"Writing all firmware for version '{package.Version}'...");

Files = new FirmwareType[]
{
Expand All @@ -72,7 +72,7 @@ protected override async ValueTask ExecuteCommand()

if (!Files.Contains(FirmwareType.OS) && UseDfu)
{
Logger.LogError($"DFU is only used for OS files. Select an OS file or remove the DFU option");
Logger?.LogError($"DFU is only used for OS files. Select an OS file or remove the DFU option");
return;
}

Expand All @@ -98,7 +98,7 @@ protected override async ValueTask ExecuteCommand()
}
catch (Exception ex)
{
Logger.LogError(ex.Message);
Logger?.LogError(ex.Message);
return;
}

Expand All @@ -113,13 +113,13 @@ protected override async ValueTask ExecuteCommand()
}
catch (Exception ex)
{
Logger.LogError($"Exception type: {ex.GetType().Name}");
Logger?.LogError($"Exception type: {ex.GetType().Name}");

// TODO: scope this to the right exception type for Win 10 access violation thing
// TODO: catch the Win10 DFU error here and change the global provider configuration to "classic"
Settings.SaveSetting(SettingsManager.PublicSettings.LibUsb, "classic");

Logger.LogWarning("This machine requires an older version of libusb. Not to worry, I'll make the change for you, but you will have to re-run this 'firmware write' command.");
Logger?.LogWarning("This machine requires an older version of libusb. Not to worry, I'll make the change for you, but you will have to re-run this 'firmware write' command.");
return;
}

Expand All @@ -145,7 +145,7 @@ protected override async ValueTask ExecuteCommand()
var connection = ConnectionManager.GetCurrentConnection();
if (connection == null)
{
Logger.LogError($"No connection path is defined");
Logger?.LogError($"No connection path is defined");
return;
}

Expand All @@ -162,8 +162,8 @@ protected override async ValueTask ExecuteCommand()

if (deviceInfo != null)
{
Logger.LogInformation($"Done.");
Logger.LogInformation(deviceInfo.ToString());
Logger?.LogInformation($"Done.");
Logger?.LogInformation(deviceInfo.ToString());
}
}
else
Expand Down Expand Up @@ -214,7 +214,7 @@ private ILibUsbDevice GetLibUsbDeviceForCurrentEnvironment()

if (existing == null)
{
Logger.LogError($"Requested version '{Version}' not found.");
Logger?.LogError($"Requested version '{Version}' not found.");
return null;
}
package = existing;
Expand Down Expand Up @@ -253,7 +253,7 @@ private async ValueTask WriteFiles()
};
connection.ConnectionMessage += (s, message) =>
{
Logger.LogInformation(message);
Logger?.LogInformation(message);
};

var package = await GetSelectedPackage();
Expand All @@ -280,14 +280,14 @@ private async ValueTask WriteFiles()
}
else
{
Logger.LogInformation($"{Environment.NewLine}Writing OS {package.Version}...");
Logger?.LogInformation($"{Environment.NewLine}Writing OS {package.Version}...");

throw new NotSupportedException("OtA writes for the OS are not yet supported");
}
}
if (Files.Contains(FirmwareType.Runtime))
{
Logger.LogInformation($"{Environment.NewLine}Writing Runtime {package.Version}...");
Logger?.LogInformation($"{Environment.NewLine}Writing Runtime {package.Version}...");

// get the path to the runtime file
var rtpath = package.GetFullyQualifiedPath(package.Runtime);
Expand All @@ -298,7 +298,7 @@ private async ValueTask WriteFiles()
}
if (Files.Contains(FirmwareType.ESP))
{
Logger.LogInformation($"{Environment.NewLine}Writing Coprocessor files...");
Logger?.LogInformation($"{Environment.NewLine}Writing Coprocessor files...");

var fileList = new string[]
{
Expand All @@ -310,7 +310,7 @@ private async ValueTask WriteFiles()
await connection.Device.WriteCoprocessorFiles(fileList, CancellationToken);
}

Logger.LogInformation($"{Environment.NewLine}");
Logger?.LogInformation($"{Environment.NewLine}");

if (wasRuntimeEnabled)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/v2/Meadow.Cli/Commands/Legacy/MonoEnableCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class MonoEnableCommand : RuntimeEnableCommand
public MonoEnableCommand(MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory)
: base(connectionManager, loggerFactory)
{
Logger.LogWarning($"Deprecated command. Use `runtime enable` instead");
Logger?.LogWarning($"Deprecated command. Use `runtime enable` instead");
}
}
2 changes: 1 addition & 1 deletion Source/v2/Meadow.Cli/Commands/Legacy/MonoStateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class MonoStateCommand : RuntimeStateCommand
public MonoStateCommand(MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory)
: base(connectionManager, loggerFactory)
{
Logger.LogWarning($"Deprecated command. Use `runtime state` instead");
Logger?.LogWarning($"Deprecated command. Use `runtime state` instead");
}
}

0 comments on commit b845e00

Please sign in to comment.