Skip to content

Commit

Permalink
Suggestions from code review. Code format error text in error details…
Browse files Browse the repository at this point in the history
…. Handling failed debug zip generation case.
  • Loading branch information
budak7273 committed Sep 3, 2024
1 parent f73b0ac commit 5a2c3e8
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 42 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
dist
*.syso


.DS_Store

# Specifically allow the provided code workspace with the multi-root workaround
!.vscode/SatisfactoryModManager.code-workspace

# Created by https://www.toptal.com/developers/gitignore/api/goland+all,go,visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=goland+all,go,visualstudiocode

Expand Down Expand Up @@ -126,8 +128,6 @@ fabric.properties
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Specifically allow the provided code workspace with the multi-root workaround
!.vscode/SatisfactoryModManager.code-workspace

# Local History for Visual Studio Code
.history/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ or run `pnpm translations` to update the translation data.

Make sure that your IDE is connecting with the frontend's installation of ESLint to get the best experience.

VSCode users, a preconfigured workspace is provided in `./vscode`
VSCode users, a preconfigured workspace is provided in `.vscode/`
that allows editing both Go and Svelte files
while maintaining correct ESLint functionality.

Expand Down
12 changes: 6 additions & 6 deletions backend/app/debug_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (a *app) generateAndSaveDebugInfo(filename string) error {
return nil
}

func (a *app) GenerateDebugInfo() bool {
func (a *app) GenerateDebugInfo() (bool, error) {
defaultFileName := fmt.Sprintf("SMMDebug-%s.zip", time.Now().UTC().Format("2006-01-02-15-04-05"))
filename, err := wailsRuntime.SaveFileDialog(appCommon.AppContext, wailsRuntime.SaveDialogOptions{
DefaultFilename: defaultFileName,
Expand All @@ -217,18 +217,18 @@ func (a *app) GenerateDebugInfo() bool {
})
if err != nil {
slog.Error("failed to open save dialog", slog.Any("error", err))
return false
return false, err

Check failure on line 220 in backend/app/debug_info.go

View workflow job for this annotation

GitHub Actions / lint-backend (ubuntu-latest)

error returned from external package is unwrapped: sig: func github.com/wailsapp/wails/v2/pkg/runtime.SaveFileDialog(ctx context.Context, dialogOptions github.com/wailsapp/wails/v2/internal/frontend.SaveDialogOptions) (string, error) (wrapcheck)

Check failure on line 220 in backend/app/debug_info.go

View workflow job for this annotation

GitHub Actions / lint-backend (macos-latest)

error returned from external package is unwrapped: sig: func github.com/wailsapp/wails/v2/pkg/runtime.SaveFileDialog(ctx context.Context, dialogOptions github.com/wailsapp/wails/v2/internal/frontend.SaveDialogOptions) (string, error) (wrapcheck)

Check failure on line 220 in backend/app/debug_info.go

View workflow job for this annotation

GitHub Actions / lint-backend (ubuntu-latest)

error returned from external package is unwrapped: sig: func github.com/wailsapp/wails/v2/pkg/runtime.SaveFileDialog(ctx context.Context, dialogOptions github.com/wailsapp/wails/v2/internal/frontend.SaveDialogOptions) (string, error) (wrapcheck)

Check failure on line 220 in backend/app/debug_info.go

View workflow job for this annotation

GitHub Actions / lint-backend (macos-latest)

error returned from external package is unwrapped: sig: func github.com/wailsapp/wails/v2/pkg/runtime.SaveFileDialog(ctx context.Context, dialogOptions github.com/wailsapp/wails/v2/internal/frontend.SaveDialogOptions) (string, error) (wrapcheck)
}
if filename == "" {
slog.Error("failed to save, filename was empty, the user might have cancelled the dialog")
return false
// user canceled the save dialog
return false, nil
}

err = a.generateAndSaveDebugInfo(filename)
if err != nil {
slog.Error("failed to generate debug info", slog.Any("error", err))
return false
return false, err
}

return true
return true, nil
}
21 changes: 13 additions & 8 deletions frontend/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,20 @@
<ErrorDetails
error={''}
fullPageMode={true}
parent={{ onClose: () => {} }}
>
<!-- Svelte slots don't support dynamic passing, so this is kinda ugly. Switch to snippets once in svelte 5 https://github.com/sveltejs/svelte/issues/7651-->
<T
slot="title"
defaultValue={noInstallsError ? 'No Satisfactory installs found' : '{invalidInstalls} invalid Satisfactory {invalidInstalls, plural, one {install} other {installs}} found'}
keyName={noInstallsError ? 'error.no_installs' : 'error.invalid_installs'}
params={{ invalidInstalls: $invalidInstalls.length }}
/>
<svelte:fragment slot="title">
{#if noInstallsError}
<T
defaultValue="No Satisfactory installs found"
keyName="error.no_installs"
/>
{:else}
<T
defaultValue={'{invalidInstalls} invalid Satisfactory {invalidInstalls, plural, one {install} other {installs}} found'}
keyName="error.invalid_installs"
params={{ invalidInstalls: $invalidInstalls.length }} />
{/if}
</svelte:fragment>
</ErrorDetails>
</div>
</ModsList>
Expand Down
88 changes: 65 additions & 23 deletions frontend/src/lib/components/modals/ErrorDetails.svelte
Original file line number Diff line number Diff line change
@@ -1,61 +1,78 @@
<script lang="ts">
import { type PopupSettings, popup } from '@skeletonlabs/skeleton';
import { getTranslate } from '@tolgee/svelte';
import T from '$lib/components/T.svelte';
import Tooltip from '$lib/components/Tooltip.svelte';
import { GenerateDebugInfo } from '$wailsjs/go/app/app';
import { BrowserOpenURL } from '$wailsjs/runtime/runtime';
import { BrowserOpenURL, LogError } from '$wailsjs/runtime/runtime';
export let parent: { onClose: () => void };
export let onClose: (() => void) | null = null;
export let fullPageMode: boolean = false;
let sectionClass: string = fullPageMode ? 'p-4' : 'px-4';
$: sectionClass = fullPageMode ? 'p-4' : 'px-4';
let openDiscordTooltipText: string;
const { t } = getTranslate();
t.subscribe((getTranslationText) => {
openDiscordTooltipText = getTranslationText(
'error.open_modding_discord.must_generate_debug_first',
'You must generate debug info first',
);
});
$: openDiscordTooltipText = $t(
'error.open_modding_discord.must_generate_debug_first',
'You must generate debug info first',
);
let allowOpeningDiscord: boolean = false;
let debugFileGenerationError: boolean = false;
let onClickGenerateDebugInfo = async () => {
let didUserSaveFile = await GenerateDebugInfo();
if (didUserSaveFile) {
try {
let didUserSaveFile = await GenerateDebugInfo();
if (didUserSaveFile) {
// Explicitly set to true -> if people click to save a second time but cancel, don't lock them out
allowOpeningDiscord = true;
}
} catch (error) {
LogError(`GenerateDebugInfo failed: ${error}`);
debugFileGenerationError = true;
// Enable the Discord button so they can report the error
allowOpeningDiscord = true;
openDiscordTooltipText = '';
} else {
alert(
'Failed to generate and save the debug info file. Did you click the Cancel button? If not, manually check your Satisfactory Mod Manager log files for more information: https://docs.ficsit.app/satisfactory-modding/latest/faq.html#Files_Logs',
);
}
};
let OpenDiscord = () => {
BrowserOpenURL('https://discord.ficsit.app/');
};
let OpenLogDocs = () => {
BrowserOpenURL('https://docs.ficsit.app/satisfactory-modding/latest/faq.html#Files_Logs');
};
const popupId = 'error-details-open-discord-popup';
const openDiscordPopup = {
event: 'hover',
target: popupId,
middleware: {
offset: 4,
},
placement: 'bottom-end',
} satisfies PopupSettings;
export let error: string;
</script>

<!-- Replace with svelte snippets once in Svelte 5 -->
<header class="card-header font-bold text-2xl text-center">
<slot name="title" />
</header>
<section class={`${sectionClass} overflow-y-auto`}>
<p>{error}</p>
<p class="font-mono">{error}</p>
</section>
<section class={sectionClass}>
<p class={fullPageMode ? 'text-base text-center' : ''}>
<T
defaultValue="Seems wrong? Click the button below to gather logs, then send the generated zip file on the modding discord in #help-using-mods."
defaultValue="Seems wrong? Click the button below to gather logs, then send the generated zip file on the modding Discord in #help-using-mods."
keyName="error.reporting_directions"
/>
</p>
</section>
<section class={sectionClass}>
<p class="text-base text-center">
<p class="text-base">
<button
class="btn text-primary-600 variant-ringed"
on:click={onClickGenerateDebugInfo}
Expand All @@ -68,19 +85,44 @@
<button
class="btn text-primary-600 variant-ringed"
disabled={!allowOpeningDiscord}
title={openDiscordTooltipText}
on:click={OpenDiscord}
use:popup={openDiscordPopup}
>
<T
defaultValue="Open the Modding Discord"
keyName="error.open_modding_discord"
/>
</button>
<Tooltip disabled={allowOpeningDiscord} {popupId}>
{openDiscordTooltipText}
</Tooltip>
</p>
</section>
{#if debugFileGenerationError}
<section class={sectionClass}>
<p class="text-base text-red-500">
<T
defaultValue="An error occurred while generating the debug file. Please manually check your Satisfactory Mod Manager log files for more information and report this on the Discord. Use the button below to open the documentation and learn how."
keyName="error.failed_to_generate_debug"
/>
</p>
</section>
<section class={sectionClass}>
<button
class="btn text-primary-600 variant-ringed"
on:click={OpenLogDocs}
>
<T
defaultValue="Open the Logging Documentation"
keyName="error.open_log_docs"
/>
</button>
</section>
{/if}
{#if !fullPageMode}
<footer class="card-footer">
<button class="btn" on:click={parent.onClose}>
<!-- Must lambda the onClose call for type matching to be happy -->
<button class="btn" on:click={onClose}>
<T defaultValue="Close" keyName="common.close" />
</button>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/components/modals/ErrorModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
style="max-height: calc(100vh - 3rem); max-width: calc(100vw - 3rem);"
class="w-[48rem] card flex flex-col gap-6"
>
<ErrorDetails {error} {parent}>
<ErrorDetails {error} onClose={parent.onClose}>
<T slot="title" defaultValue="Something went wrong" keyName="error.title" />
</ErrorDetails>
</div>

0 comments on commit 5a2c3e8

Please sign in to comment.