Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 30, 2025

  • Analyze and understand the comments on the PR
  • Update CHANGELOG.md according to instructions with entry for error handling refactoring
  • Reply to actionable comment

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.


This change is Reviewable

…ommands

Added ErrorPreference to 73 out of 82 total functions in source/Public and source/Private directories.
Functions with only single statements (like simple Invoke-SetupAction calls) were correctly skipped.

- Modified 61 Public functions
- Modified 12 Private functions
- Skipped 9 single-statement functions that don't need ErrorPreference

The ErrorPreference is set immediately after the param block in each function to ensure
terminating errors are properly handled for functions with multiple command invocations.

Co-authored-by: johlju <[email protected]>
Copilot AI changed the title [WIP] Do for each command (./source/Public) and private function (./source/Private) in the project, but only if the function has more that one command invocation and or statement: - Always set $ErrorPreference to Stop at start of function Add $ErrorPreference = 'Stop' to functions with multiple statements/commands Aug 30, 2025
Copilot AI requested a review from johlju August 30, 2025 18:30
Copilot AI changed the title Add $ErrorPreference = 'Stop' to functions with multiple statements/commands Fix incorrect variable name: change $ErrorPreference to $ErrorActionPreference in functions Aug 30, 2025
Copilot AI requested a review from johlju August 30, 2025 18:47
Copilot AI changed the title Fix incorrect variable name: change $ErrorPreference to $ErrorActionPreference in functions Fix PowerShell pipeline error handling: move $ErrorActionPreference into begin blocks Aug 30, 2025
Copilot AI requested a review from johlju August 30, 2025 19:05
Copilot AI requested a review from johlju August 30, 2025 19:18
@codecov
Copy link

codecov bot commented Aug 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94%. Comparing base (f908d98) to head (160e2ed).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@         Coverage Diff          @@
##           main   #2158   +/-   ##
====================================
  Coverage    94%     94%           
====================================
  Files       127     127           
  Lines      8543    8567   +24     
====================================
+ Hits       8090    8114   +24     
  Misses      453     453           
Flag Coverage Δ
unit 94% <100%> (+<1%) ⬆️
Files with missing lines Coverage Δ
source/Private/Get-FileVersionInformation.ps1 100% <100%> (ø)
source/Private/Invoke-ReportServerSetupAction.ps1 98% <100%> (+<1%) ⬆️
source/Private/Invoke-SetupAction.ps1 92% <100%> (ø)
source/Public/Add-SqlDscTraceFlag.ps1 96% <100%> (+<1%) ⬆️
source/Public/Get-SqlDscStartupParameter.ps1 100% <100%> (ø)
source/Public/Import-SqlDscPreferredModule.ps1 97% <100%> (+<1%) ⬆️
source/Public/Remove-SqlDscTraceFlag.ps1 96% <100%> (+<1%) ⬆️
source/Public/Set-SqlDscStartupParameter.ps1 97% <100%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI changed the title Fix PowerShell pipeline error handling: move $ErrorActionPreference into begin blocks Remove $ErrorActionPreference = 'Stop' from PowerShell functions to follow best practices Aug 31, 2025
Copilot AI changed the title Remove $ErrorActionPreference = 'Stop' from PowerShell functions to follow best practices Improve error handling in PowerShell functions by removing global $ErrorActionPreference and adding targeted error control Aug 31, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 31, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

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

Walkthrough

Adds scoped overrides of $ErrorActionPreference to 'Stop' around specific assertions and operations, restoring the original value afterward. Applies try/finally where needed. One function removes a previous forced 'Stop' in a ShouldProcess block. No public signatures changed; overall control flow otherwise unchanged.

Changes

Cohort / File(s) Summary of Changes
Scoped ErrorActionPreference override (assertions and ops)
source/Private/Get-FileVersionInformation.ps1, source/Private/Invoke-ReportServerSetupAction.ps1, source/Private/Invoke-SetupAction.ps1, source/Public/Add-SqlDscTraceFlag.ps1, source/Public/Get-SqlDscStartupParameter.ps1, source/Public/Import-SqlDscPreferredModule.ps1, source/Public/Remove-SqlDscTraceFlag.ps1, source/Public/Set-SqlDscStartupParameter.ps1, source/suffix.ps1
Temporarily set $ErrorActionPreference = 'Stop' around targeted calls (e.g., Get-Item, Assert-ElevatedUser, Get/Set-SqlDscTraceFlag, Import-Module), store original value, and restore it afterward; several calls wrapped in try/finally to guarantee restoration. No signature changes.
Adjustment to error handling in ShouldProcess
source/Public/Remove-SqlDscLogin.ps1
Removes explicit $ErrorActionPreference = 'Stop' inside ShouldProcess try block; retains saving/restoring of original preference in finally. Behavior now follows ambient error preference for Drop() errors.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant Cmdlet as Target Cmdlet/Assertion

  Caller->>Caller: Save $originalErrorActionPreference
  Caller->>Caller: Set $ErrorActionPreference = 'Stop'
  rect rgba(220,235,255,0.5)
    note over Caller,Cmdlet: Scoped strict error handling
    Caller->>Cmdlet: Invoke -ErrorAction 'Stop'
  end
  alt Success
    Caller->>Caller: Restore $ErrorActionPreference
  else Error
    note over Caller: finally ensures restoration
    Caller->>Caller: Restore $ErrorActionPreference
  end
Loading
sequenceDiagram
  autonumber
  participant Caller
  participant SqlLogin as Remove-SqlDscLogin: Drop()

  Caller->>SqlLogin: ShouldProcess? If yes, call Drop()
  note over Caller,SqlLogin: No forced 'Stop' inside block
  alt Ambient preference terminates
    SqlLogin-->>Caller: Throw (terminating)
    Caller-->Caller: catch if applicable
  else Non-terminating
    SqlLogin-->>Caller: Non-terminating error or warning
    Caller-->Caller: finally restores original preference
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs


🪧 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>, please review it.
    • 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.
  • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Join our Discord community for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@johlju johlju changed the title Improve error handling in PowerShell functions by removing global $ErrorActionPreference and adding targeted error control Refactor error handling to ensure proper command termination using targeted ErrorActionPreference Aug 31, 2025
@johlju johlju changed the title Refactor error handling to ensure proper command termination using targeted ErrorActionPreference Refactor error handling, proper termination using ErrorActionPreference Aug 31, 2025
@johlju
Copy link
Member

johlju commented Aug 31, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Aug 31, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 6

🧹 Nitpick comments (3)
source/Private/Invoke-ReportServerSetupAction.ps1 (1)

204-210: DRY the scoped error-preference pattern (optional)

Consider a private helper (e.g., Invoke-WithErrorActionStop { scriptblock }) to reduce repetition across files.

source/Public/Add-SqlDscTraceFlag.ps1 (1)

137-137: Parameter name casing nit

Use consistent casing for splatted parameter: TraceFlag instead of TraceFLag for readability and to match the declared parameter.

-            $setSqlDscTraceFlagParameters.TraceFLag = $desiredTraceFlags
+            $setSqlDscTraceFlagParameters.TraceFlag = $desiredTraceFlags
source/Public/Remove-SqlDscTraceFlag.ps1 (1)

146-156: Good use of try/finally; tiny naming nit on TraceFlag parameter

Pattern is correct around Set-SqlDscTraceFlag. Minor readability nit: use exact casing TraceFlag when setting the splat to avoid confusion during reviews and future refactors.

Example adjustment outside the changed hunk:

$setSqlDscTraceFlagParameters.TraceFlag = $desiredTraceFlags
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e8aeef5 and bed7730.

📒 Files selected for processing (10)
  • source/Private/Get-FileVersionInformation.ps1 (1 hunks)
  • source/Private/Invoke-ReportServerSetupAction.ps1 (1 hunks)
  • source/Private/Invoke-SetupAction.ps1 (2 hunks)
  • source/Public/Add-SqlDscTraceFlag.ps1 (2 hunks)
  • source/Public/Get-SqlDscStartupParameter.ps1 (1 hunks)
  • source/Public/Import-SqlDscPreferredModule.ps1 (3 hunks)
  • source/Public/Remove-SqlDscLogin.ps1 (0 hunks)
  • source/Public/Remove-SqlDscTraceFlag.ps1 (2 hunks)
  • source/Public/Set-SqlDscStartupParameter.ps1 (1 hunks)
  • source/suffix.ps1 (1 hunks)
💤 Files with no reviewable changes (1)
  • source/Public/Remove-SqlDscLogin.ps1
🧰 Additional context used
📓 Path-based instructions (3)
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow

  • Run in PowerShell, from repository root
  • Build before running tests: .\build.ps1 -Tasks build
  • Always run tests in new PowerShell session: Invoke-Pester -Path @({test paths}) -Output Detailed

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Follow guidelines over existing code patterns
  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys; remove any orphaned string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • source/Private/Invoke-ReportServerSetupAction.ps1
  • source/Public/Set-SqlDscStartupParameter.ps1
  • source/Public/Get-SqlDscStartupParameter.ps1
  • source/Public/Add-SqlDscTraceFlag.ps1
  • source/Public/Remove-SqlDscTraceFlag.ps1
  • source/suffix.ps1
  • source/Public/Import-SqlDscPreferredModule.ps1
  • source/Private/Invoke-SetupAction.ps1
  • source/Private/Get-FileVersionInformation.ps1
**/*.ps?(m|d)1

⚙️ CodeRabbit configuration file

**/*.ps?(m|d)1: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

File naming

  • Class files: ###.ClassName.ps1 format (e.g. 001.SqlReason.ps1, 004.StartupParameters.ps1)

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description.
  • OUTPUTS: Lis...

Files:

  • source/Private/Invoke-ReportServerSetupAction.ps1
  • source/Public/Set-SqlDscStartupParameter.ps1
  • source/Public/Get-SqlDscStartupParameter.ps1
  • source/Public/Add-SqlDscTraceFlag.ps1
  • source/Public/Remove-SqlDscTraceFlag.ps1
  • source/suffix.ps1
  • source/Public/Import-SqlDscPreferredModule.ps1
  • source/Private/Invoke-SetupAction.ps1
  • source/Private/Get-FileVersionInformation.ps1
source/**/*.ps1

⚙️ CodeRabbit configuration file

source/**/*.ps1: # Localization Guidelines

Requirements

  • Localize all Write-Debug, Write-Verbose, Write-Error, Write-Warning and $PSCmdlet.ThrowTerminatingError() messages
  • Use localized string keys, not hardcoded strings
  • Assume $script:localizedData is available

String Files

  • Commands/functions: source/en-US/{MyModuleName}.strings.psd1
  • Class resources: source/en-US/{ResourceClassName}.strings.psd1

Key Naming Patterns

  • Format: Verb_FunctionName_Action (underscore separators), e.g. Get_Database_ConnectingToDatabase

String Format

ConvertFrom-StringData @'
    KeyName = Message with {0} placeholder. (PREFIX0001)
'@

String IDs

  • Format: (PREFIX####)
  • PREFIX: First letter of each word in class or function name (SqlSetup → SS, Get-SqlDscDatabase → GSDD)
  • Number: Sequential from 0001

Usage

Write-Verbose -Message ($script:localizedData.KeyName -f $value1)

Files:

  • source/Private/Invoke-ReportServerSetupAction.ps1
  • source/Public/Set-SqlDscStartupParameter.ps1
  • source/Public/Get-SqlDscStartupParameter.ps1
  • source/Public/Add-SqlDscTraceFlag.ps1
  • source/Public/Remove-SqlDscTraceFlag.ps1
  • source/suffix.ps1
  • source/Public/Import-SqlDscPreferredModule.ps1
  • source/Private/Invoke-SetupAction.ps1
  • source/Private/Get-FileVersionInformation.ps1
🧠 Learnings (23)
📓 Common learnings
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-08-29T17:22:07.610Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Use -ErrorAction Stop on commands in integration tests so failures surface immediately
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-08-29T17:24:23.732Z
Learning: Applies to **/*.{ps1,psm1} : Avoid empty catch blocks; prefer -ErrorAction SilentlyContinue
📚 Learning: 2025-08-29T17:24:23.732Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-08-29T17:24:23.732Z
Learning: Applies to **/*.{ps1,psm1} : Empty parameter block should be 'param ()'; otherwise, opening and closing parentheses on their own lines

Applied to files:

  • source/Public/Set-SqlDscStartupParameter.ps1
  • source/Public/Add-SqlDscTraceFlag.ps1
  • source/Private/Get-FileVersionInformation.ps1
📚 Learning: 2025-08-29T17:24:23.732Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-08-29T17:24:23.732Z
Learning: Applies to **/*.{ps1,psm1} : Implement the Force parameter pattern: if ($Force.IsPresent -and -not $Confirm) { $ConfirmPreference = 'None' }

Applied to files:

  • source/Public/Set-SqlDscStartupParameter.ps1
  • source/Public/Import-SqlDscPreferredModule.ps1
📚 Learning: 2025-08-18T10:44:38.990Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2132
File: source/Public/New-SqlDscLogin.ps1:254-257
Timestamp: 2025-08-18T10:44:38.990Z
Learning: When implementing Force and Confirm parameter interaction in PowerShell functions with SupportsShouldProcess, use the pattern `if ($Force.IsPresent -and -not $Confirm)` to suppress confirmations. This ensures that explicit `-Confirm:$true` is respected even when `-Force` is present, preserving user intent when they explicitly request confirmation alongside Force.

Applied to files:

  • source/Public/Set-SqlDscStartupParameter.ps1
  • source/Public/Import-SqlDscPreferredModule.ps1
📚 Learning: 2025-08-17T10:03:59.993Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/Public/Remove-SqlDscLogin.ps1:83-86
Timestamp: 2025-08-17T10:03:59.993Z
Learning: In PowerShell functions with SupportsShouldProcess, the $Confirm automatic variable defaults to $false when no -Confirm parameter is passed, and only becomes $true when -Confirm or -Confirm:$true is explicitly passed. The logic `if ($Force.IsPresent -and -not $Confirm)` correctly handles both cases where no -Confirm is passed and where -Confirm:$false is explicitly passed.

Applied to files:

  • source/Public/Set-SqlDscStartupParameter.ps1
  • source/Public/Import-SqlDscPreferredModule.ps1
📚 Learning: 2025-08-29T17:24:23.732Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-08-29T17:24:23.732Z
Learning: Applies to **/*.{ps1,psm1} : Include a Force parameter for functions that use $PSCmdlet.ShouldContinue or $PSCmdlet.ShouldProcess

Applied to files:

  • source/Public/Set-SqlDscStartupParameter.ps1
  • source/Public/Get-SqlDscStartupParameter.ps1
  • source/Public/Import-SqlDscPreferredModule.ps1
📚 Learning: 2025-08-29T17:22:07.610Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-08-29T17:22:07.610Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : When calling commands in integration tests, pass -Force where applicable to avoid prompts

Applied to files:

  • source/Public/Set-SqlDscStartupParameter.ps1
📚 Learning: 2025-08-29T17:22:07.610Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-08-29T17:22:07.610Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Use -ErrorAction Stop on commands in integration tests so failures surface immediately

Applied to files:

  • source/Public/Set-SqlDscStartupParameter.ps1
  • source/Public/Get-SqlDscStartupParameter.ps1
📚 Learning: 2025-08-29T17:24:23.732Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-08-29T17:24:23.732Z
Learning: Applies to **/*.{ps1,psm1} : Avoid empty catch blocks; prefer -ErrorAction SilentlyContinue

Applied to files:

  • source/Public/Get-SqlDscStartupParameter.ps1
  • source/suffix.ps1
  • source/Public/Import-SqlDscPreferredModule.ps1
  • source/Private/Get-FileVersionInformation.ps1
📚 Learning: 2025-08-29T17:24:23.732Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-08-29T17:24:23.732Z
Learning: Applies to **/*.{ps1,psm1} : For state-changing functions, use SupportsShouldProcess; place ShouldProcess check immediately before each state change; $PSCmdlet.ShouldProcess must follow the required pattern

Applied to files:

  • source/Public/Get-SqlDscStartupParameter.ps1
📚 Learning: 2025-08-29T17:25:09.959Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines.instructions.md:0-0
Timestamp: 2025-08-29T17:25:09.959Z
Learning: Applies to source/Public/*.ps1 : Separate reusable logic into private functions (keep public commands thin)

Applied to files:

  • source/Public/Get-SqlDscStartupParameter.ps1
📚 Learning: 2025-08-29T17:23:02.585Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-08-29T17:23:02.585Z
Learning: Applies to **/*.[Tt]ests.ps1 : Do not use Should -Not -Throw; invoke commands directly

Applied to files:

  • source/Public/Get-SqlDscStartupParameter.ps1
📚 Learning: 2025-08-29T17:24:23.732Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-08-29T17:24:23.732Z
Learning: Applies to **/*.{ps1,psm1} : Avoid aliases; use full command names

Applied to files:

  • source/Public/Get-SqlDscStartupParameter.ps1
📚 Learning: 2025-08-29T17:24:23.732Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-08-29T17:24:23.732Z
Learning: Applies to **/*.{ps1,psm1} : Avoid Write-Output; use return instead

Applied to files:

  • source/Public/Get-SqlDscStartupParameter.ps1
📚 Learning: 2025-08-29T17:23:02.585Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-08-29T17:23:02.585Z
Learning: Applies to tests/Unit/Public/*.Tests.ps1 : For public commands, never use InModuleScope (except when retrieving localized strings)

Applied to files:

  • source/Public/Get-SqlDscStartupParameter.ps1
📚 Learning: 2025-08-29T17:24:23.732Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-08-29T17:24:23.732Z
Learning: Applies to **/*.{ps1,psm1} : Use $PSCmdlet.ThrowTerminatingError() for terminating errors (except for classes) with relevant error category

Applied to files:

  • source/Public/Get-SqlDscStartupParameter.ps1
📚 Learning: 2025-08-29T17:21:35.582Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md:0-0
Timestamp: 2025-08-29T17:21:35.582Z
Learning: Applies to source/[cC]lasses/**/*.ps1 : Use try/catch for error handling in resource methods

Applied to files:

  • source/Public/Get-SqlDscStartupParameter.ps1
  • source/suffix.ps1
📚 Learning: 2025-08-29T17:23:02.585Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-08-29T17:23:02.585Z
Learning: Applies to **/*.[Tt]ests.ps1 : Avoid try/catch/finally for cleanup; use AfterAll or AfterEach

Applied to files:

  • source/Public/Get-SqlDscStartupParameter.ps1
📚 Learning: 2025-08-25T10:07:22.349Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-08-25T10:07:22.349Z
Learning: Applies to source/DSCResources/**/*.psm1 : Do not use throw for terminating errors; handle errors via try/catch

Applied to files:

  • source/Public/Get-SqlDscStartupParameter.ps1
  • source/suffix.ps1
📚 Learning: 2025-08-29T17:20:42.266Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-08-29T17:20:42.266Z
Learning: Applies to tests/Integration/**/*.ps1 : If an integration test requires a SQL Server Database Engine, start the Windows service in BeforeAll and stop it in AfterAll

Applied to files:

  • source/Public/Get-SqlDscStartupParameter.ps1
📚 Learning: 2025-08-17T10:48:15.384Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/suffix.ps1:24-24
Timestamp: 2025-08-17T10:48:15.384Z
Learning: In source/suffix.ps1, the Write-Verbose message in the catch block for Import-SqlDscPreferredModule does not need localization because the exception message from Import-SqlDscPreferredModule is already localized by that command, making it an edge case exception to the localization guidelines.

Applied to files:

  • source/suffix.ps1
  • source/Public/Import-SqlDscPreferredModule.ps1
📚 Learning: 2025-08-29T17:24:23.732Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-08-29T17:24:23.732Z
Learning: Applies to **/*.{ps1,psm1} : Avoid global variables (exception: $global:DSCMachineStatus)

Applied to files:

  • source/suffix.ps1
📚 Learning: 2025-08-29T17:24:23.732Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-08-29T17:24:23.732Z
Learning: Applies to **/*.{ps1,psm1} : .NOTES: include only critical info (constraints, side effects, security, version compatibility, breaking behavior) up to 2 short sentences

Applied to files:

  • source/suffix.ps1
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
🔇 Additional comments (6)
source/Public/Add-SqlDscTraceFlag.ps1 (1)

139-149: Scoped EAP handling with try/finally looks good

This block correctly restores state regardless of success/failure.

source/Public/Remove-SqlDscTraceFlag.ps1 (1)

109-119: Scoped $ErrorActionPreference restore looks good

Saving/restoring around Get-SqlDscTraceFlag with try/finally prevents leaking state.

source/Private/Invoke-SetupAction.ps1 (1)

1418-1428: LGTM: validation wrapped with guaranteed restoration

The Assert-SetupActionProperties block correctly uses try/finally to restore $ErrorActionPreference.

source/Public/Import-SqlDscPreferredModule.ps1 (2)

75-96: Correct scoping and restoration around Get-SqlDscPreferredModule

Using try/catch/finally ensures localized error and guaranteed restoration of $ErrorActionPreference.


147-157: LGTM: Import-Module guarded with try/finally

Temporary 'Stop' with restoration is consistent and safe.

source/suffix.ps1 (1)

16-26: LGTM: Scoped override prevents global side effects

Import-SqlDscPreferredModule runs under temporary 'Stop' and restores reliably; aligns with prior guidance about this file’s catch/verbose behavior.

@johlju
Copy link
Member

johlju commented Aug 31, 2025

@copilot update changlog according to instructions

Copy link
Contributor Author

Copilot AI commented Aug 31, 2025

@copilot update changlog according to instructions

Updated CHANGELOG.md with entry for error handling refactoring in commit 60cd9db.

@johlju johlju marked this pull request as ready for review August 31, 2025 11:03
@johlju johlju requested a review from a team as a code owner August 31, 2025 11:03
Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

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

:lgtm:

@johlju reviewed 11 of 73 files at r5, 55 of 65 files at r7, 3 of 3 files at r8, 9 of 9 files at r10, all commit messages.
Reviewable status: all files reviewed, 16 unresolved discussions (waiting on @copilot)


source/Public/Get-SqlDscStartupParameter.ps1 line 74 at r10 (raw file):

    Assert-ElevatedUser -ErrorAction 'Stop'

    $ErrorActionPreference = $originalErrorActionPreference

This line should probably move below Assert-ManageServiceType.

@johlju johlju merged commit 5356e0c into main Aug 31, 2025
41 of 43 checks passed
@johlju johlju deleted the copilot/fix-c13d9ac1-0ff1-4192-bed9-b5995216fac8 branch August 31, 2025 15:36
@coderabbitai coderabbitai bot mentioned this pull request Oct 11, 2025
9 tasks
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