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

Updates Examples With New Package Names, Adds Warning, Fix Thread Panic #252

Merged

Conversation

dvonthenen
Copy link
Contributor

@dvonthenen dvonthenen commented Jun 25, 2024

Proposed changes

Addresses: #251

This PR does three things:

  • Implements a fix for Attempt to Recover from Panic in Threads (Listen, KeepAlive, AutoFlush) #251. In a situation when we panic in a thread we created, we emit the error and close the client immediately. This will cause the client to reconnect properly in this situation.
  • Implements the Warning messages and callback.
  • Finishes updating all examples to migrate from the deprecated package names to the new ones. This is why you see deletion of the //lint:ignore comment. We are no longer using deprecated package names.

Tested on all examples.

Types of changes

What types of changes does your code introduce to the community Go SDK?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update or tests (if none of the other choices apply)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc
  • I have lint'ed all of my code using repo standards
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

NA

Summary by CodeRabbit

  • New Features

    • Introduced support for the listen/v1/rest and listen/v1/websocket API packages.
    • Added new error handling and recovery mechanisms for WebSocket connections.
  • Improvements

    • Enhanced clarity and consistency in log messages and method names across the speak and listen clients.
    • Updated SDK version to v1.4.0.
  • Deprecations

    • Deprecated certain client aliases and functions in favor of more descriptive names.
  • Refactor

    • Unified import paths and updated client instantiation methods for better readability and efficiency.

Copy link

coderabbitai bot commented Jun 25, 2024

Important

Review skipped

Review was skipped due to path filters

Files ignored due to path filters (48)
  • examples/manage/balances/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/manage/invitations-new-RENAME/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/manage/invitations/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/manage/keys/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/manage/members/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/manage/projects/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/manage/scopes/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/manage/usage/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/speech-to-text/rest/callback/callback/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/speech-to-text/rest/callback/endpoint/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/speech-to-text/rest/file-new-RENAME/Bueller-Life-moves-pretty-fast.mp3 is excluded by !**/*.mp3, !examples/**, !!tests/expected_failures/**
  • examples/speech-to-text/rest/file-new-RENAME/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/speech-to-text/rest/file/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/speech-to-text/rest/intent/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/speech-to-text/rest/sentiment/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/speech-to-text/rest/stream/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/speech-to-text/rest/summary/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/speech-to-text/rest/topic/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/speech-to-text/rest/url/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/speech-to-text/websocket/http/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/speech-to-text/websocket/microphone-new-RENAME/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/speech-to-text/websocket/microphone/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/speech-to-text/websocket/replay/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/speech-to-text/websocket/test/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/text-to-speech/rest/file-new-RENAME/hello-world/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/text-to-speech/rest/file/hello-world/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/text-to-speech/rest/file/woodchuck/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/text-to-speech/rest/stream/hello-world/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/text-to-speech/rest/stream/woodchuck/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/text-to-speech/rest/writer/hello-world/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/text-to-speech/rest/writer/woodchuck/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/text-to-speech/websocket/interactive/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • examples/text-to-speech/websocket/simple/main.go is excluded by !examples/**, !!tests/expected_failures/**
  • pkg/api/speak/v1/websocket/default.go is excluded by !!tests/expected_failures/**
  • pkg/api/speak/v1/websocket/interfaces/constants.go is excluded by !!tests/expected_failures/**
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go is excluded by !!tests/expected_failures/**
  • pkg/api/speak/v1/websocket/interfaces/types.go is excluded by !!tests/expected_failures/**
  • pkg/api/speak/v1/websocket/router.go is excluded by !!tests/expected_failures/**
  • pkg/client/common/v1/common.go is excluded by !!tests/expected_failures/**
  • pkg/client/interfaces/utils.go is excluded by !!tests/expected_failures/**
  • pkg/client/interfaces/v1/utils.go is excluded by !!tests/expected_failures/**
  • pkg/client/listen/client.go is excluded by !!tests/expected_failures/**
  • pkg/client/listen/v1/websocket/client.go is excluded by !!tests/expected_failures/**
  • pkg/client/listen/v1/websocket/constants.go is excluded by !!tests/expected_failures/**
  • pkg/client/speak/client.go is excluded by !!tests/expected_failures/**
  • pkg/client/speak/v1/rest/client.go is excluded by !!tests/expected_failures/**
  • pkg/client/speak/v1/websocket/client.go is excluded by !!tests/expected_failures/**
  • pkg/client/speak/v1/websocket/constants.go is excluded by !!tests/expected_failures/**

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent updates to the Deepgram Go SDK involve various import path changes, package refactoring, function deprecations, and updates to logging and error handling. Key modifications include reorganizing client packages for better consistency, adding recovery mechanisms for panic situations, adjusting SDK versioning, and refining the instantiation processes across different API interfaces including manage, listen, speak, and websocket.

Changes

Files/Directories Change Summary
examples/manage/* Updated import paths from rest to manage in all main.go files.
examples/speech-to-text/rest/* Switched API package from prerecorded/v1 to listen/v1/rest.
examples/speech-to-text/websocket/* Changed imports from live/v1/interfaces to listen/v1/websocket/interfaces and updated client instantiation.
examples/text-to-speech/rest/* Updated import path from speak/v1 to speak/v1/rest and modified client instantiation processes.
examples/text-to-speech/rest/writer/* Updated import paths and client instantiation in hello-world and woodchuck modules.
examples/text-to-speech/websocket/* Refactored text input sending process for better readability in interactive and simple modules.
pkg/client/speak/v1/websocket/* Updated log messages and function names for clarity and consistency.
pkg/client/interfaces/v1/utils.go Updated SDK version constant from "v1.2.0" to "v1.4.0".
pkg/client/listen/client.go Added and deprecated aliases for listenv1rest.Client and listenv1ws.Client to streamline client usage.
pkg/client/listen/v1/websocket/* Added deferred recovery functions to handle panics in Client struct methods.
pkg/client/speak/client.go Added deprecation notice for NewWithDefaults function and introduced NewRESTWithDefaults.
pkg/client/listen/v1/websocket/constants.go Introduced error constant ErrFatalPanicRecovered for handling fatal panics.
pkg/client/speak/v1/websocket/constants.go Introduced error constant ErrFatalPanicRecovered for handling fatal panics.

Sequence Diagram(s)

The changes do not include specific new features or modifications to the control flow that would necessitate sequence diagrams for better understanding. The updates largely revolve around refactoring and error-handling improvements without altering the primary interactions between components in a manner that significantly changes the overall behavior or architecture.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dvonthenen dvonthenen changed the title Updates Examples to Use New Package Names Updates Examples to Use New Package Names, Fix Thread Panic Jun 25, 2024
@dvonthenen dvonthenen force-pushed the update-examples-using-new-struct branch 2 times, most recently from 530dd67 to 65d6392 Compare June 25, 2024 17:39
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6543ebc and 65d6392.

Files ignored due to path filters (1)
  • examples/speech-to-text/rest/file-new-RENAME/Bueller-Life-moves-pretty-fast.mp3 is excluded by !**/*.mp3
Files selected for processing (31)
  • examples/manage/balances/main.go (1 hunks)
  • examples/manage/invitations/main.go (1 hunks)
  • examples/manage/keys/main.go (1 hunks)
  • examples/manage/members/main.go (1 hunks)
  • examples/manage/projects/main.go (1 hunks)
  • examples/manage/scopes/main.go (1 hunks)
  • examples/manage/usage/main.go (1 hunks)
  • examples/speech-to-text/rest/callback/callback/main.go (2 hunks)
  • examples/speech-to-text/rest/callback/endpoint/main.go (1 hunks)
  • examples/speech-to-text/rest/file/main.go (2 hunks)
  • examples/speech-to-text/rest/intent/main.go (2 hunks)
  • examples/speech-to-text/rest/sentiment/main.go (2 hunks)
  • examples/speech-to-text/rest/stream/main.go (2 hunks)
  • examples/speech-to-text/rest/summary/main.go (2 hunks)
  • examples/speech-to-text/rest/topic/main.go (2 hunks)
  • examples/speech-to-text/rest/url/main.go (2 hunks)
  • examples/speech-to-text/websocket/http/main.go (2 hunks)
  • examples/speech-to-text/websocket/microphone/main.go (2 hunks)
  • examples/speech-to-text/websocket/replay/main.go (2 hunks)
  • examples/speech-to-text/websocket/test/main.go (2 hunks)
  • examples/text-to-speech/rest/file/hello-world/main.go (2 hunks)
  • examples/text-to-speech/rest/file/woodchuck/main.go (2 hunks)
  • examples/text-to-speech/rest/stream/hello-world/main.go (2 hunks)
  • examples/text-to-speech/rest/stream/woodchuck/main.go (2 hunks)
  • examples/text-to-speech/rest/writer/hello-world/main.go (2 hunks)
  • examples/text-to-speech/rest/writer/woodchuck/main.go (2 hunks)
  • pkg/client/listen/client.go (7 hunks)
  • pkg/client/listen/v1/websocket/client.go (7 hunks)
  • pkg/client/listen/v1/websocket/constants.go (1 hunks)
  • pkg/client/speak/v1/websocket/client.go (21 hunks)
  • pkg/client/speak/v1/websocket/constants.go (1 hunks)
Files skipped from review due to trivial changes (7)
  • examples/manage/balances/main.go
  • examples/manage/invitations/main.go
  • examples/manage/keys/main.go
  • examples/manage/members/main.go
  • examples/manage/projects/main.go
  • examples/speech-to-text/rest/callback/endpoint/main.go
  • pkg/client/listen/v1/websocket/constants.go
Additional comments not posted (36)
pkg/client/speak/v1/websocket/constants.go (1)

53-53: Addition of ErrFatalPanicRecovered is appropriate for enhanced error handling.

The addition of this constant helps in better managing fatal errors that are caught and recovered, aligning with the PR's objective to handle panics more gracefully. This is a good practice in robust error management.

examples/text-to-speech/rest/file/hello-world/main.go (1)

15-15: Updated API usage and client instantiation in example.

The changes correctly reflect the migration from the old speak package to the new api package under speak/v1/rest, ensuring the example is up-to-date with the latest package structure. This is crucial for maintaining consistency and clarity in the SDK's documentation and examples.

Also applies to: 41-41

examples/speech-to-text/rest/callback/callback/main.go (1)

15-15: Updated API usage and client instantiation in example.

The changes correctly reflect the migration from the old prerecorded package to the new listen/v1/rest package, ensuring the example is up-to-date with the latest package structure. This is crucial for maintaining consistency and clarity in the SDK's documentation and examples.

Also applies to: 17-17, 33-34

examples/speech-to-text/rest/intent/main.go (1)

15-15: Updated API usage and client instantiation in example.

The changes correctly reflect the migration from the old prerecorded package to the new listen/v1/rest package, ensuring the example is up-to-date with the latest package structure. This is crucial for maintaining consistency and clarity in the SDK's documentation and examples.

Also applies to: 17-17, 43-44

examples/speech-to-text/rest/sentiment/main.go (1)

15-15: Updated API usage and client instantiation in example.

The changes correctly reflect the migration from the old prerecorded package to the new listen/v1/rest package, ensuring the example is up-to-date with the latest package structure. This is crucial for maintaining consistency and clarity in the SDK's documentation and examples.

Also applies to: 17-17, 43-44

examples/speech-to-text/rest/summary/main.go (2)

15-17: Updated import paths to reflect new package structure.

The changes in the import paths from prerecorded to listen reflect the updated package structure which seems aligned with the PR's objectives to update deprecated package names.


43-44: Client instantiation updated to new API conventions.

The client instantiation now uses NewRESTWithDefaults and New from the api package, which is consistent with the updated package structure and naming conventions.

examples/speech-to-text/rest/topic/main.go (2)

15-17: Consistent update of import paths across examples.

Similar to other files, the update of import paths here ensures consistency across the examples, aligning with the new package structure.


43-44: Consistency in client instantiation across examples.

The client instantiation methods are consistently updated across examples, which is crucial for maintaining uniformity in API usage.

examples/text-to-speech/rest/writer/hello-world/main.go (2)

15-15: Updated import path for TTS API.

The import path update from speak to speak/v1/rest reflects the new API structure, making it clearer and more specific.


39-39: Correct instantiation of TTS client using new API methods.

The instantiation of the TTS client using New from the updated API package is correct and aligns with the new naming conventions.

examples/text-to-speech/rest/file/woodchuck/main.go (2)

15-15: Updated import path and client instantiation for TTS.

The changes in import paths and client instantiation methods are consistent with the new API structure and naming conventions.


41-41: Consistent client instantiation method used.

The use of New for client instantiation is consistent across the updated examples, ensuring uniformity in the API's usage.

examples/speech-to-text/rest/url/main.go (2)

15-17: Import paths updated to align with new API structure.

The updates to the import paths are consistent with the changes across other examples, reflecting the new API structure.


41-42: Proper instantiation of client using updated API methods.

The instantiation of the client using NewRESTWithDefaults and New is correct and aligns with the updated API conventions.

examples/speech-to-text/rest/stream/main.go (2)

15-17: Updated import paths match the new structure.

The changes in import paths align with the PR's objectives to update to new package names. This helps in maintaining consistency across the codebase.


42-43: Correct instantiation of new client objects.

The instantiation of client objects using the new API paths is correct and reflects the updates mentioned in the PR objectives.

examples/text-to-speech/rest/writer/woodchuck/main.go (2)

15-15: Updated import paths are consistent with new package structure.

The import paths have been updated to reflect the new package names, which is in line with the PR's objectives.


39-39: Client instantiation uses the updated API.

The new client instantiation method api.New is used correctly here, reflecting the package updates intended by the PR.

examples/speech-to-text/websocket/http/main.go (2)

16-16: Updated import paths align with the new client structure.

The updated import path for the client package is correct and reflects the intended changes in the PR.


40-40: Correct instantiation of WebSocket client for demo purposes.

The new method NewWebSocketForDemo is used properly for client instantiation, aligning with the updates to the WebSocket API in the PR.

examples/text-to-speech/rest/stream/hello-world/main.go (2)

15-15: Updated import paths correctly reflect the new API structure.

The import paths have been updated appropriately, consistent with the PR's objectives to use the new package names.


39-39: Proper use of new client instantiation method.

The instantiation of the client using the new api.New method is correct and reflects the intended package updates by the PR.

examples/speech-to-text/websocket/replay/main.go (2)

17-17: Updated import path for the client package is correct.

The import path has been updated to align with the new structure, which is consistent with the PR's objectives.


40-40: Correct instantiation of WebSocket client for demo purposes.

The use of NewWebSocketForDemo for client instantiation is correct and aligns with the updates to the WebSocket API as intended in the PR.

examples/text-to-speech/rest/stream/woodchuck/main.go (1)

39-39: Client instantiation updated to new API.

The instantiation of the api client using api.New(c) correctly follows the updated import paths and is consistent with the new package structure.

examples/speech-to-text/rest/file/main.go (2)

44-47: Client instantiation updated to new API.

The instantiation of the api client using api.New(c) correctly follows the updated import paths and is consistent with the new package structure.


15-17: Updated import paths to reflect package renaming.

The changes in the import paths from prerecorded to listen/v1/rest correctly reflect the new package structure. This should be verified across the project for consistency.

Verification successful

Updated import paths to reflect package renaming.

The changes in the import paths from prerecorded to listen/v1/rest correctly reflect the new package structure. The new package paths are consistently used across the project, confirming the renaming is correctly implemented.

  • All instances of the new package github.com/deepgram/deepgram-go-sdk/pkg/api/listen/v1/rest are found in various files, including tests and examples.
  • The new client package github.com/deepgram/deepgram-go-sdk/pkg/client/listen is also consistently used across multiple files.
  • The interfaces package github.com/deepgram/deepgram-go-sdk/pkg/client/interfaces is widely used across the project.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify consistency of package name changes across the project.

# Test: Search for the old package name usage. Expect: No occurrences.
rg --type go $'github.com/deepgram/deepgram-go-sdk/pkg/api/prerecorded/v1'

Length of output: 73



Script:

#!/bin/bash
# Description: Verify the new package name usage across the project.

# Test: Search for the new package name usage.
rg --type go $'github.com/deepgram/deepgram-go-sdk/pkg/api/listen/v1/rest'

# Test: Search for the new client package name usage.
rg --type go $'github.com/deepgram/deepgram-go-sdk/pkg/client/listen'

# Test: Search for the new interfaces package name usage.
rg --type go $'github.com/deepgram/deepgram-go-sdk/pkg/client/interfaces'

Length of output: 12183

examples/speech-to-text/websocket/test/main.go (2)

58-58: Client instantiation updated to new API.

The instantiation of the client using client.NewWebSocket correctly follows the updated import paths and is consistent with the new package structure.


17-17: Updated import paths to reflect package renaming.

The change in the import path from live to listen under the websocket directory is part of the package renaming efforts. This should be verified across the project for consistency.

Verification successful

Verified the consistency of package name changes across the project.

The new package name listen has been correctly and consistently integrated across the project.

  • pkg/client/prerecorded/legacy.go
  • pkg/client/live/legacy.go
  • pkg/client/listen/client.go
  • tests/unit_test/prerecorded_test.go
  • pkg/api/listen/v1/rest/rest.go
  • tests/daily_test/prerecorded_test.go
  • tests/edge_cases/keepalive/main.go
  • docs.go
  • tests/edge_cases/cancel/main.go
  • tests/edge_cases/timeout/main.go
  • tests/edge_cases/reconnect_client/main.go
  • tests/edge_cases/failed_retry/main.go
  • examples/speech-to-text/websocket/test/main.go
  • examples/speech-to-text/rest/summary/main.go
  • examples/speech-to-text/rest/topic/main.go
  • examples/speech-to-text/rest/stream/main.go
  • examples/speech-to-text/rest/url/main.go
  • examples/speech-to-text/websocket/microphone/main.go
  • examples/speech-to-text/websocket/replay/main.go
  • examples/speech-to-text/rest/file/main.go
  • examples/speech-to-text/websocket/http/main.go
  • examples/speech-to-text/rest/sentiment/main.go
  • examples/speech-to-text/rest/intent/main.go
  • examples/speech-to-text/rest/callback/callback/main.go
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify consistency of package name changes across the project.

# Test: Search for the old package name usage. Expect: No occurrences.
rg --type go $'github.com/deepgram/deepgram-go-sdk/pkg/client/live'

Length of output: 66



Script:

#!/bin/bash
# Description: Verify consistency of new package name usage across the project.

# Test: Search for the new package name usage. Expect: Occurrences in relevant files.
rg --type go $'github.com/deepgram/deepgram-go-sdk/pkg/client/listen'

Length of output: 2711

examples/speech-to-text/websocket/microphone/main.go (1)

15-18: Updated import paths and client instantiation approved.

The changes to the import paths and the client package instantiation align with the new package structure as described in the PR summary and the AI-generated summary. This is a necessary update to ensure the example uses the latest SDK packages.

pkg/client/listen/client.go (1)

26-33: Review of deprecation notices and alias updates.

All deprecation notices and alias updates are consistent with the changes described in the AI-generated summary. These changes help guide developers towards the newer API methods and maintain backward compatibility for now.
[APROVED]

However, ensure that the deprecated methods are removed in future releases as indicated.

Also applies to: 44-48, 60-64, 75-79, 90-94, 111-115, 135-139, 159-162

pkg/client/speak/v1/websocket/client.go (1)

Line range hint 90-124: Review of updated logging and error handling.

The changes in logging and error handling are extensive and improve the clarity and traceability of the client's operations. The use of structured logging and detailed error messages will aid in debugging and maintaining the client.

However, consider adding more comments explaining the logic behind some complex operations, especially in the error handling and connection management areas, to improve maintainability.

+ // This block handles the reconnection logic in case the initial connection fails.
+ // It attempts to reconnect a specified number of times before giving up.

Also applies to: 163-193, 254-287, 299-416, 453-479, 486-513, 523-556, 563-574, 581-592, 597-614, 620-647, 663-696

pkg/client/listen/v1/websocket/client.go (3)

295-316: Improved error handling and thread safety in the listen function.

The addition of panic recovery in the listen function is a crucial improvement for enhancing the robustness of the websocket client. This change ensures that unexpected panics do not cause the entire application to crash, instead allowing for a controlled closure of the websocket connection. This is particularly important in a multi-threaded environment where such panics can lead to unpredictable behavior or deadlocks.

The implementation logs the panic occurrence, attempts to send an error callback, and ensures the websocket is closed properly. This approach not only handles the immediate error but also maintains the integrity of the application by preventing further complications.

+	defer func() {
+		if r := recover(); r != nil {
+			klog.V(1).Infof("Panic triggered\n")
+			err := ErrFatalPanicRecovered
+			sendErr := c.sendError(err)
+			if sendErr != nil {
+				klog.V(1).Infof("listen: Fatal socket error. Err: %v\n", sendErr)
+			}
+			c.closeWs(true)
+			klog.V(6).Infof("live.listen() LEAVE\n")
+			return
+		}
+	}()

This pattern of error handling should be consistently applied across all functions that involve similar risks, ensuring that the application can gracefully handle failures and continue operation. It's advisable to review all other similar functions to ensure they follow a similar pattern for error handling and resource cleanup.


743-760: Consistent error handling and recovery in the ping thread.

The changes in the ping function mirror those in the listen function, providing a consistent approach to handling panics across different parts of the application. This is essential for maintaining a stable and reliable system, especially when dealing with external systems or services that might behave unpredictably.

+	defer func() {
+		if r := recover(); r != nil {
+			klog.V(1).Infof("Panic triggered\n")
+			err := ErrFatalPanicRecovered
+			sendErr := c.sendError(err)
+			if sendErr != nil {
+				klog.V(1).Infof("listen: Fatal socket error. Err: %v\n", sendErr)
+			}
+			c.closeWs(true)
+			klog.V(6).Infof("live.ping() LEAVE\n")
+			return
+		}
+	}()

This implementation ensures that the application can recover from unexpected errors during the keepalive process, which is critical for maintaining a live connection with external services. It's recommended to ensure that all network-related threads in the application utilize a similar pattern to enhance overall error resilience.

[APROVED]


793-810: Robust error handling in the flush function.

Implementing panic recovery in the flush function is another step towards making the websocket client more resilient. This ensures that even if an unexpected error occurs during the flushing process, the application can recover gracefully without affecting the overall stability.

+	defer func() {
+		if r := recover(); r != nil {
+			klog.V(1).Infof("Panic triggered\n")
+			err := ErrFatalPanicRecovered
+			sendErr := c.sendError(err)
+			if sendErr != nil {
+				klog.V(1).Infof("listen: Fatal socket error. Err: %v\n", sendErr)
+			}
+			c.closeWs(true)
+			klog.V(6).Infof("live.flush() LEAVE\n")
+			return
+		}
+	}()

This change not only prevents the application from crashing but also ensures that resources are properly cleaned up, maintaining the integrity and performance of the system. Consistent error handling across all components that interact with external systems or services is crucial for building a reliable and maintainable application.

examples/manage/usage/main.go Show resolved Hide resolved
examples/manage/scopes/main.go Show resolved Hide resolved
@dvonthenen dvonthenen force-pushed the update-examples-using-new-struct branch 2 times, most recently from 0403a63 to 43b1b20 Compare June 26, 2024 14:59
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 65d6392 and 43b1b20.

Files ignored due to path filters (1)
  • examples/speech-to-text/rest/file-new-RENAME/Bueller-Life-moves-pretty-fast.mp3 is excluded by !**/*.mp3
Files selected for processing (33)
  • examples/manage/balances/main.go (1 hunks)
  • examples/manage/invitations/main.go (1 hunks)
  • examples/manage/keys/main.go (1 hunks)
  • examples/manage/members/main.go (1 hunks)
  • examples/manage/projects/main.go (1 hunks)
  • examples/manage/scopes/main.go (1 hunks)
  • examples/manage/usage/main.go (1 hunks)
  • examples/speech-to-text/rest/callback/callback/main.go (2 hunks)
  • examples/speech-to-text/rest/callback/endpoint/main.go (1 hunks)
  • examples/speech-to-text/rest/file/main.go (2 hunks)
  • examples/speech-to-text/rest/intent/main.go (2 hunks)
  • examples/speech-to-text/rest/sentiment/main.go (2 hunks)
  • examples/speech-to-text/rest/stream/main.go (2 hunks)
  • examples/speech-to-text/rest/summary/main.go (2 hunks)
  • examples/speech-to-text/rest/topic/main.go (2 hunks)
  • examples/speech-to-text/rest/url/main.go (2 hunks)
  • examples/speech-to-text/websocket/http/main.go (2 hunks)
  • examples/speech-to-text/websocket/microphone/main.go (2 hunks)
  • examples/speech-to-text/websocket/replay/main.go (2 hunks)
  • examples/speech-to-text/websocket/test/main.go (2 hunks)
  • examples/text-to-speech/rest/file/hello-world/main.go (2 hunks)
  • examples/text-to-speech/rest/file/woodchuck/main.go (2 hunks)
  • examples/text-to-speech/rest/stream/hello-world/main.go (2 hunks)
  • examples/text-to-speech/rest/stream/woodchuck/main.go (2 hunks)
  • examples/text-to-speech/rest/writer/hello-world/main.go (2 hunks)
  • examples/text-to-speech/rest/writer/woodchuck/main.go (2 hunks)
  • pkg/client/interfaces/v1/utils.go (1 hunks)
  • pkg/client/listen/client.go (7 hunks)
  • pkg/client/listen/v1/websocket/client.go (7 hunks)
  • pkg/client/listen/v1/websocket/constants.go (1 hunks)
  • pkg/client/speak/client.go (2 hunks)
  • pkg/client/speak/v1/websocket/client.go (21 hunks)
  • pkg/client/speak/v1/websocket/constants.go (1 hunks)
Files skipped from review as they are similar to previous changes (31)
  • examples/manage/balances/main.go
  • examples/manage/invitations/main.go
  • examples/manage/keys/main.go
  • examples/manage/members/main.go
  • examples/manage/projects/main.go
  • examples/manage/scopes/main.go
  • examples/manage/usage/main.go
  • examples/speech-to-text/rest/callback/callback/main.go
  • examples/speech-to-text/rest/callback/endpoint/main.go
  • examples/speech-to-text/rest/file/main.go
  • examples/speech-to-text/rest/intent/main.go
  • examples/speech-to-text/rest/sentiment/main.go
  • examples/speech-to-text/rest/stream/main.go
  • examples/speech-to-text/rest/summary/main.go
  • examples/speech-to-text/rest/topic/main.go
  • examples/speech-to-text/rest/url/main.go
  • examples/speech-to-text/websocket/http/main.go
  • examples/speech-to-text/websocket/microphone/main.go
  • examples/speech-to-text/websocket/replay/main.go
  • examples/speech-to-text/websocket/test/main.go
  • examples/text-to-speech/rest/file/hello-world/main.go
  • examples/text-to-speech/rest/file/woodchuck/main.go
  • examples/text-to-speech/rest/stream/hello-world/main.go
  • examples/text-to-speech/rest/stream/woodchuck/main.go
  • examples/text-to-speech/rest/writer/hello-world/main.go
  • examples/text-to-speech/rest/writer/woodchuck/main.go
  • pkg/client/listen/client.go
  • pkg/client/listen/v1/websocket/client.go
  • pkg/client/listen/v1/websocket/constants.go
  • pkg/client/speak/v1/websocket/client.go
  • pkg/client/speak/v1/websocket/constants.go
Additional comments not posted (3)
pkg/client/interfaces/v1/utils.go (1)

18-18: SDK version updated to v1.4.0.

Ensure all references to sdkVersion across the project are updated to reflect this new version.

Verification successful

SDK version updated to v1.4.0.

All references to sdkVersion have been updated correctly.

  • pkg/client/interfaces/v1/utils.go: sdkVersion string = "v1.4.0"
  • pkg/client/interfaces/v1/utils.go: var DgAgent string = "@deepgram/sdk/" + sdkVersion + " go/" + goVersion()
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all references to `sdkVersion` are updated.

# Test: Search for outdated SDK version references. Expect: No occurrences of "v1.2.0".
rg --type go $'v1.2.0'

Length of output: 21



Script:

#!/bin/bash
# Description: Verify that all references to `sdkVersion` are updated to "v1.4.0".

# Test: Search for all occurrences of `sdkVersion` and verify the updated version "v1.4.0".
rg --type go 'sdkVersion'

Length of output: 197

pkg/client/speak/client.go (2)

39-40: Deprecation of NewWithDefaults in favor of NewREST.

Consider adding a more detailed explanation or migration guide in the deprecation notice to assist users in transitioning to the new method.


60-69: General API updates and function introductions.

Review all documentation and example code to ensure they reflect the new function names and API structure. Update any remaining references to deprecated functions.

pkg/client/speak/client.go Show resolved Hide resolved
@dvonthenen dvonthenen force-pushed the update-examples-using-new-struct branch from 43b1b20 to 845c737 Compare June 26, 2024 15:58
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
examples/text-to-speech/websocket/simple/main.go (1)

Line range hint 109-123: Review new error handling and method calls in main function.

The addition of SpeakWithText and Flush methods in the main function is a good change for clarity and modularity. However, the error messages for both methods are identical, which might be confusing during debugging. Consider differentiating these messages or handling them more gracefully.

- fmt.Printf("Error sending text input: %v\n", err)
+ fmt.Printf("Error during SpeakWithText: %v\n", err)
- fmt.Printf("Error sending text input: %v\n", err)
+ fmt.Printf("Error during Flush: %v\n", err)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 43b1b20 and 845c737.

Files ignored due to path filters (1)
  • examples/speech-to-text/rest/file-new-RENAME/Bueller-Life-moves-pretty-fast.mp3 is excluded by !**/*.mp3
Files selected for processing (35)
  • examples/manage/balances/main.go (1 hunks)
  • examples/manage/invitations/main.go (1 hunks)
  • examples/manage/keys/main.go (1 hunks)
  • examples/manage/members/main.go (1 hunks)
  • examples/manage/projects/main.go (1 hunks)
  • examples/manage/scopes/main.go (1 hunks)
  • examples/manage/usage/main.go (1 hunks)
  • examples/speech-to-text/rest/callback/callback/main.go (2 hunks)
  • examples/speech-to-text/rest/callback/endpoint/main.go (1 hunks)
  • examples/speech-to-text/rest/file/main.go (2 hunks)
  • examples/speech-to-text/rest/intent/main.go (2 hunks)
  • examples/speech-to-text/rest/sentiment/main.go (2 hunks)
  • examples/speech-to-text/rest/stream/main.go (2 hunks)
  • examples/speech-to-text/rest/summary/main.go (2 hunks)
  • examples/speech-to-text/rest/topic/main.go (2 hunks)
  • examples/speech-to-text/rest/url/main.go (2 hunks)
  • examples/speech-to-text/websocket/http/main.go (2 hunks)
  • examples/speech-to-text/websocket/microphone/main.go (2 hunks)
  • examples/speech-to-text/websocket/replay/main.go (2 hunks)
  • examples/speech-to-text/websocket/test/main.go (2 hunks)
  • examples/text-to-speech/rest/file/hello-world/main.go (2 hunks)
  • examples/text-to-speech/rest/file/woodchuck/main.go (2 hunks)
  • examples/text-to-speech/rest/stream/hello-world/main.go (2 hunks)
  • examples/text-to-speech/rest/stream/woodchuck/main.go (2 hunks)
  • examples/text-to-speech/rest/writer/hello-world/main.go (2 hunks)
  • examples/text-to-speech/rest/writer/woodchuck/main.go (2 hunks)
  • examples/text-to-speech/websocket/interactive/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple/main.go (1 hunks)
  • pkg/client/interfaces/v1/utils.go (1 hunks)
  • pkg/client/listen/client.go (7 hunks)
  • pkg/client/listen/v1/websocket/client.go (7 hunks)
  • pkg/client/listen/v1/websocket/constants.go (1 hunks)
  • pkg/client/speak/client.go (2 hunks)
  • pkg/client/speak/v1/websocket/client.go (21 hunks)
  • pkg/client/speak/v1/websocket/constants.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • examples/text-to-speech/websocket/interactive/main.go
Files skipped from review as they are similar to previous changes (33)
  • examples/manage/balances/main.go
  • examples/manage/invitations/main.go
  • examples/manage/keys/main.go
  • examples/manage/members/main.go
  • examples/manage/projects/main.go
  • examples/manage/scopes/main.go
  • examples/manage/usage/main.go
  • examples/speech-to-text/rest/callback/callback/main.go
  • examples/speech-to-text/rest/callback/endpoint/main.go
  • examples/speech-to-text/rest/file/main.go
  • examples/speech-to-text/rest/intent/main.go
  • examples/speech-to-text/rest/sentiment/main.go
  • examples/speech-to-text/rest/stream/main.go
  • examples/speech-to-text/rest/summary/main.go
  • examples/speech-to-text/rest/topic/main.go
  • examples/speech-to-text/rest/url/main.go
  • examples/speech-to-text/websocket/http/main.go
  • examples/speech-to-text/websocket/microphone/main.go
  • examples/speech-to-text/websocket/replay/main.go
  • examples/speech-to-text/websocket/test/main.go
  • examples/text-to-speech/rest/file/hello-world/main.go
  • examples/text-to-speech/rest/file/woodchuck/main.go
  • examples/text-to-speech/rest/stream/hello-world/main.go
  • examples/text-to-speech/rest/stream/woodchuck/main.go
  • examples/text-to-speech/rest/writer/hello-world/main.go
  • examples/text-to-speech/rest/writer/woodchuck/main.go
  • pkg/client/interfaces/v1/utils.go
  • pkg/client/listen/client.go
  • pkg/client/listen/v1/websocket/client.go
  • pkg/client/listen/v1/websocket/constants.go
  • pkg/client/speak/client.go
  • pkg/client/speak/v1/websocket/client.go
  • pkg/client/speak/v1/websocket/constants.go
Additional comments not posted (2)
examples/text-to-speech/websocket/simple/main.go (2)

Line range hint 10-16: Check import paths for consistency.

The import paths align with the new package structure as described in the PR. However, ensure all examples and documentation are updated consistently to reflect these changes.


Line range hint 21-47: Ensure proper error handling in callback methods.

The callback methods handle different types of WebSocket messages appropriately. Each method logs relevant information, which is good for debugging. However, consider enhancing the error logging with more context or additional details if available.

@dvonthenen dvonthenen force-pushed the update-examples-using-new-struct branch from 845c737 to 650c0b0 Compare June 27, 2024 00:22
@dvonthenen dvonthenen changed the title Updates Examples to Use New Package Names, Fix Thread Panic Updates Examples With New Package Names, Adds Warning, Fix Thread Panic Jun 27, 2024
@dvonthenen dvonthenen force-pushed the update-examples-using-new-struct branch 3 times, most recently from edd8f9e to 3d1e5c0 Compare June 27, 2024 19:03
@dvonthenen dvonthenen force-pushed the update-examples-using-new-struct branch from 3d1e5c0 to 2986e7e Compare June 27, 2024 20:04
@dvonthenen dvonthenen merged commit c795e99 into deepgram:main Jun 28, 2024
2 checks passed
@dvonthenen dvonthenen deleted the update-examples-using-new-struct branch June 28, 2024 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants