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

chore: Misc polish #10

Merged
merged 19 commits into from
Dec 31, 2024
Merged

chore: Misc polish #10

merged 19 commits into from
Dec 31, 2024

Conversation

t1mmen
Copy link
Owner

@t1mmen t1mmen commented Dec 31, 2024

PR Type

Enhancement, Bug fix


Description

Major UI and functionality improvements:

  • Added database connection state management and error handling across the application
  • Added force options to build and apply commands to override change detection
  • Added update notifier to inform users of new package versions
  • Improved UI feedback and error states throughout the application
  • Added support for customizing migration filename prefix
  • Improved logging and error messages
  • Added reusable quit handler component
  • Better handling of database connection failures
  • Code cleanup and refactoring for better maintainability

Changes walkthrough 📝

Relevant files
Enhancement
10 files
cli.tsx
Add update notifier for new package versions                         
+4/-0     
apply.tsx
Add force option to apply command                                               
+25/-6   
build.tsx
Add force option to build command                                               
+21/-4   
index.tsx
Improve UI state handling and database connection checks 
+35/-10 
register.tsx
Improve register command UI and error handling                     
+9/-5     
watch.tsx
Improve watch mode UI and database connection handling     
+34/-30 
Branding.tsx
Add database connection status to branding component         
+6/-4     
Quittable.tsx
Add reusable quit handler component                                           
+27/-0   
useDatabaseConnection.ts
Add database connection state management hook                       
+80/-0   
templateManager.ts
Improve template manager logging and error handling           
+31/-19 
Error handling
1 files
_app.tsx
Add database connection error handling in app root             
+33/-3   
Additional files
16 files
moody-scissors-pay.md +5/-0     
rare-squids-grow.md +5/-0     
red-balloons-notice.md +5/-0     
shiny-mangos-shave.md +5/-0     
thin-singers-wink.md +5/-0     
README.md +12/-12 
package-lock.json +605/-50
package.json +6/-4     
repomix.config.json +11/-2   
fake_migration_files.sh +11/-0   
help.tsx [link]   
types.ts +2/-1     
config.ts +1/-0     
databaseConnection.ts +21/-7   
executeCommand.ts +47/-0   
logger.ts +2/-0     

💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

Copy link

changeset-bot bot commented Dec 31, 2024

🦋 Changeset detected

Latest commit: 511edb7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@t1mmen/srtd Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

qodo-merge-pro-for-open-source bot commented Dec 31, 2024

CI Failure Feedback 🧐

(Checks updated until commit a3738b1)

Action: test (20.x)

Failed stage: Run Biome [❌]

Failure summary:

The action failed due to two issues:
1. Code formatting errors were found in
./src/utils/executeCommand.ts. The formatter encountered parsing errors and aborted the formatting
process.
2. Codecov test results upload failed because no JUnit XML reports were found. The action
was expecting test result files but found 0 test_results files to report.

Relevant error logs:
1:  ##[group]Operating System
2:  Ubuntu
...

327:  �[0m�[0m  �[0m�[0m  �[0m�[0m�[1m51 │ �[0m�[0m �[0m�[0m �[0m�[0m �[0m�[0m �[0m�[0m}�[0m�[0m)�[0m�[0m;�[0m�[0m
328:  �[0m�[0m  �[0m�[0m  �[0m�[0m�[1m52 │ �[0m�[0m �[0m�[0m �[0m�[0m}�[0m�[0m)�[0m�[0m;�[0m�[0m
329:  �[0m�[0m  �[0m�[0m�[1m�[31m>�[0m�[0m �[0m�[0m�[1m53 │ �[0m�[0m}�[0m�[0m
330:  �[0m�[0m  �[0m�[0m �[0m�[0m �[0m�[0m�[1m   │ �[0m�[0m�[1m�[31m^�[0m�[0m
331:  �[0m�[0m  �[0m�[0m  �[0m�[0m�[1m54 │ �[0m�[0m
332:  �[0m�[0m  �[0m�[0m
333:  �[0m
334:  �[0m./src/utils/executeCommand.ts�[0m�[0m �[0m�[0mformat�[0m�[0m �[0m�[0m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━�[0m�[0m
335:  �[0m�[0m  �[0m�[0m�[1m�[31m✖�[0m�[0m �[0m�[0m�[31mCode formatting aborted due to parsing errors. To format code with errors, enable the 'formatter.formatWithErrors' option.�[0m�[0m
336:  �[0m�[0m  �[0m�[0m
337:  �[0m
338:  �[0mci�[0m�[0m �[0m�[0m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━�[0m�[0m
339:  �[0m�[0m  �[0m�[0m�[1m�[31m✖�[0m�[0m �[0m�[0m�[31mSome �[0m�[0m�[1m�[31merrors�[0m�[0m�[31m were emitted while �[0m�[0m�[1m�[31mrunning checks�[0m�[0m�[31m.�[0m�[0m
340:  �[0m�[0m  �[0m�[0m
341:  �[0m
342:  �[0m�[34mChecked �[0m�[0m�[34m47�[0m�[0m�[34m �[0m�[0m�[34mfiles�[0m�[0m�[34m in �[0m�[0m�[34m31�[0m�[0m�[2m�[34mms�[0m�[0m�[34m.�[0m�[0m�[34m No fixes applied.�[0m�[0m
343:  �[0m�[0m�[31mFound �[0m�[0m�[31m7�[0m�[0m�[31m errors.�[0m
344:  ##[error]Process completed with exit code 1.
...

357:  gpg: Signature made Sat Dec  7 16:07:53 2024 UTC
358:  gpg:                using RSA key 27034E7FDB850E0BBC2C62FF806BB28AED779869
359:  gpg: Good signature from "Codecov Uploader (Codecov Uploader Verification Key) <security@codecov.io>" [unknown]
360:  gpg: WARNING: This key is not certified with a trusted signature!
361:  gpg:          There is no indication that the signature belongs to the owner.
362:  Primary key fingerprint: 2703 4E7F DB85 0E0B BC2C  62FF 806B B28A ED77 9869
363:  ==> Uploader SHASUM verified (bb3c8dcaf649c47ce0321ce153ebc781b88421c97c584b1956fb62c3399db755  codecov)
364:  ==> Running version latest
365:  Could not pull latest version information: SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
366:  ==> Running command '/home/runner/work/_actions/codecov/test-results-action/v1/dist/codecov do-upload'
367:  [command]/home/runner/work/_actions/codecov/test-results-action/v1/dist/codecov do-upload -C a3738b1543e758b528b82f70fafd16de7c514304 --report-type test_results
368:  info - 2024-12-31 12:32:22,951 -- ci service found: github-actions
369:  warning - 2024-12-31 12:32:22,959 -- No config file could be found. Ignoring config.
370:  info - 2024-12-31 12:32:22,974 -- Found 0 test_results files to report
371:  Error: No JUnit XML reports found. Please review our documentation (https://docs.codecov.com/docs/test-result-ingestion-beta) to generate and upload the file.
372:  ##[warning]Codecov: 
373:                          Failed to properly upload report: The process '/home/runner/work/_actions/codecov/test-results-action/v1/dist/codecov' failed with exit code 1

✨ CI feedback usage guide:

The CI feedback tool (/checks) automatically triggers when a PR has a failed check.
The tool analyzes the failed checks and provides several feedbacks:

  • Failed stage
  • Failed test name
  • Failure summary
  • Relevant error logs

In addition to being automatically triggered, the tool can also be invoked manually by commenting on a PR:

/checks "https://github.com/{repo_name}/actions/runs/{run_number}/job/{job_number}"

where {repo_name} is the name of the repository, {run_number} is the run number of the failed check, and {job_number} is the job number of the failed check.

Configuration options

  • enable_auto_checks_feedback - if set to true, the tool will automatically provide feedback when a check is failed. Default is true.
  • excluded_checks_list - a list of checks to exclude from the feedback, for example: ["check1", "check2"]. Default is an empty list.
  • enable_help_text - if set to true, the tool will provide a help message with the feedback. Default is true.
  • persistent_comment - if set to true, the tool will overwrite a previous checks comment with the new feedback. Default is true.
  • final_update_message - if persistent_comment is true and updating a previous checks message, the tool will also create a new message: "Persistent checks updated to latest commit". Default is true.

See more information about the checks tool in the docs.

Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Error Handling

The database connection error handling in processTemplates() could be improved. Currently it returns early with an empty result object when connection fails, but should consider propagating the error.

  this.log('Failed to connect to database, cannot proceed. Is Supabase running?', 'error');
  return result;
}
Connection Management

The retryConnection function silently retries on failure when silent=true. This could mask important connection issues and make debugging harder.

  if (!silent) {
    logger.warn(`Connection failed, retrying in ${RETRY_DELAY}ms...`);
  }
  await new Promise(resolve => setTimeout(resolve, RETRY_DELAY));
  return retryConnection(params);
}

Copy link
Contributor

qodo-merge-pro-for-open-source bot commented Dec 31, 2024

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Score
Possible issue
Ensure proper cleanup of database connections to prevent resource leaks

Add proper cleanup of database resources by ensuring client release in case of
errors during template processing.

src/lib/templateManager.ts [232-239]

-const isConnected = await testConnection();
-if (isConnected) {
+let client;
+try {
+  client = await connect();
   this.log('Connected to database', 'success');
-} else {
+} catch (error) {
   this.log('Failed to connect to database, cannot proceed. Is Supabase running?', 'error');
   return result;
+} finally {
+  client?.release();
 }
  • Apply this suggestion
Suggestion importance[1-10]: 8

Why: The suggestion addresses a potential resource leak by ensuring database connections are properly released, which is critical for application stability and resource management.

8
✅ Implement command execution timeout to prevent indefinite hanging of processes

Add timeout handling for command execution to prevent hanging processes. The current
implementation could potentially hang indefinitely.

src/utils/executeCommand.ts [10-14]

 export async function executeCommand(
   command: string,
   args: string[] = [],
-  options: ExecuteCommandOptions = { silent: true }
+  options: ExecuteCommandOptions = { silent: true, timeout?: number }
 ): Promise<boolean> {
+  const timeout = options.timeout || 30000; // 30 second default timeout
+  const timeoutPromise = new Promise<boolean>((_, reject) => {
+    setTimeout(() => reject(new Error(`Command timed out after ${timeout}ms`)), timeout);
+  });
+  return Promise.race([executeCommandImpl(command, args, options), timeoutPromise]);
+}

[Suggestion has been applied]

Suggestion importance[1-10]: 7

Why: Adding timeout handling is important for preventing hung processes and ensuring commands complete in a reasonable time, improving application reliability.

7
General
Add error handling for directory operations to prevent silent failures

Add input validation to prevent potential issues with directory creation and file
operations. Check if the directory exists and has write permissions before
proceeding.

scripts/fake_migration_files.sh [1-4]

 #!/bin/bash
 
 TEMPLATE_DIR="supabase/migrations-templates"
-mkdir -p "$TEMPLATE_DIR"
+if ! mkdir -p "$TEMPLATE_DIR" 2>/dev/null; then
+    echo "Error: Unable to create directory $TEMPLATE_DIR"
+    exit 1
+fi
+if [ ! -w "$TEMPLATE_DIR" ]; then
+    echo "Error: No write permission in $TEMPLATE_DIR"
+    exit 1
+fi
  • Apply this suggestion
Suggestion importance[1-10]: 7

Why: The suggestion adds important error handling for directory creation and permission checks, which can prevent silent failures and improve script reliability in different environments.

7
Add proper error logging for database connection failures to aid in troubleshooting

Add error handling for the database connection test to prevent silent failures. The
current implementation swallows all errors which could mask critical connection
issues.

src/utils/databaseConnection.ts [52-61]

 export async function testConnection(): Promise<boolean> {
   try {
     const client = await connect();
     await client.query('SELECT 1');
     client.release();
     return true;
-  } catch {
+  } catch (error) {
+    logger.debug(`Database connection test failed: ${error instanceof Error ? error.message : String(error)}`);
     return false;
   }
 }
  • Apply this suggestion
Suggestion importance[1-10]: 6

Why: Adding detailed error logging for database connection failures would help with debugging issues, though the current implementation still functions correctly. The suggestion improves observability without affecting core functionality.

6

@t1mmen t1mmen changed the title Misc polish chore: Misc polish Dec 31, 2024
@github-actions github-actions bot added the chore label Dec 31, 2024
Copy link

codecov bot commented Dec 31, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

t1mmen and others added 3 commits December 31, 2024 13:31
Co-authored-by: qodo-merge-pro-for-open-source[bot] <189517486+qodo-merge-pro-for-open-source[bot]@users.noreply.github.com>
@t1mmen t1mmen merged commit 748a1c8 into main Dec 31, 2024
5 checks passed
@t1mmen t1mmen deleted the misc-polish branch December 31, 2024 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant