Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Also drops one line of excess logging.

Signed-off-by: Mark Yen <[email protected]>
  • Loading branch information
mook-as committed Aug 12, 2024
1 parent 1254bc6 commit c6c3467
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/rancher-desktop/integrations/pathManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export interface PathManager {
/** The PathManagementStrategy that corresponds to the implementation. */
readonly strategy: PathManagementStrategy
/**
* Makes real any changes to the system. Should be idempotent, and should not
* throw any exceptions.
* Applies changes to the system. Should be idempotent, and should not throw
* any exceptions.
*/
enforce(): Promise<void>
/**
Expand Down
2 changes: 1 addition & 1 deletion pkg/rancher-desktop/integrations/pathManagerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class RcFilePathManager implements PathManager {
try {
await manageLinesInFile(filePath, lines, desiredPresent);
mainEvents.emit('diagnostics-event', 'path-management', { fileName, error: undefined });
} catch (error) {
} catch (error: any) {
mainEvents.emit('diagnostics-event', 'path-management', { fileName, error });
throw error;
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/rancher-desktop/main/diagnostics/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ export class DiagnosticsManager {
this.checkers = diagnostics ? Promise.resolve(diagnostics) : (async() => {
const imports = (await Promise.all([
import('./connectedToInternet'),
import('./pathManagement'),
import('./dockerCliSymlinks'),
import('./kubeConfigSymlink'),
import('./kubeContext'),
import('./limaDarwin'),
import('./mockForScreenshots'),
import('./pathManagement'),
import('./rdBinInShell'),
import('./testCheckers'),
import('./wslFromStore'),
Expand Down
7 changes: 4 additions & 3 deletions pkg/rancher-desktop/main/diagnostics/pathManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { DiagnosticsCategory, DiagnosticsChecker, DiagnosticsCheckerResult, Diag

import { ErrorHasExtendedAttributes, ErrorNotRegularFile, ErrorWritingFile } from '@pkg/integrations/manageLinesInFile';
import mainEvents from '@pkg/main/mainEvents';
import Logging from '@pkg/utils/logging';

const console = Logging.diagnostics;
const cachedResults: Record<string, DiagnosticsCheckerResult> = {};

/**
* Check for any errors raised from handling path management (i.e. handling of
* ~/.bashrc and related files) and report them to the user.
*/
const CheckPathManagement: DiagnosticsChecker = {
id: 'PATH_MANAGEMENT',
category: DiagnosticsCategory.Utilities,
Expand All @@ -24,7 +26,6 @@ const CheckPathManagement: DiagnosticsChecker = {
};

mainEvents.on('diagnostics-event', (id, state) => {
console.log('diagnostics-event', id, state);
if (id !== 'path-management') {
return;
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/rancher-desktop/main/mainEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ interface MainEventNames {
* @param id The diagnostic identifier.
* @param state The new state for the diagnostic.
*/
'diagnostics-event'(id: string, state: any): void;
'diagnostics-event'<K extends keyof DiagnosticsEventPayload>(id: K, state: DiagnosticsEventPayload[K]): void;

/**
* Emitted when an extension is uninstalled via the extension manager.
Expand Down Expand Up @@ -144,6 +144,14 @@ interface MainEventNames {
'dialog-info'(args: Record<string, string>): void;
}

/**
* DiagnosticsEventPayload defines the data that will be passed on a
* 'diagnostics-event' event.
*/
type DiagnosticsEventPayload = {
'path-management': { fileName: string; error: Error | undefined };
};

/**
* Helper type definition to check if the given event name is a handler (i.e.
* has a return value) instead of an event (i.e. returns void).
Expand Down

0 comments on commit c6c3467

Please sign in to comment.