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

Move to using sqlite3_errmsg to extract a contextual error for SQLite failures #2352

Merged
merged 2 commits into from
Jul 21, 2022

Conversation

JohnMcPMS
Copy link
Member

@JohnMcPMS JohnMcPMS commented Jul 21, 2022

Change

Use sqlite3_errmsg to get an error message with actual context as opposed to the string for the error code. We can always look up the error code string if needed, and we will get the string for the HRESULT version in the logs as well.

For instance, the message for the new test is now:

Msg:[no such table: simpletest2]

Rather than the prior "Bad SQL" type default value.

Validation

All unit tests pass, manually confirmed more useful error messages in at least some cases.

Microsoft Reviewers: Open in CodeFlow

@JohnMcPMS JohnMcPMS requested a review from a team as a code owner July 21, 2022 06:32
@github-actions
Copy link

github-actions bot commented Jul 21, 2022

@check-spelling-bot Report

Unrecognized words, please review:

  • errmsg
Previously acknowledged words that are now absent activatable amd Archs dsc efgh enr FWW Globals hackathon LPITEMIDLIST lww mytool OSVERSION Packagedx parametermap pathpaths PIDLIST symlink Uninitialize WDAG whatif wsb
To accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the git@github.com:JohnMcPMS/winget-cli.git repository
on the sql-err branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spelling/expect.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
}

comment_json=$(mktemp)
curl -L -s -S \
  --header "Content-Type: application/json" \
  "https://api.github.com/repos/microsoft/winget-cli/issues/comments/1191095899" > "$comment_json"
comment_body=$(mktemp)
jq -r .body < "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")
  

patch_add=$(perl -e '$/=undef;
$_=<>;
s{<details>.*}{}s;
s{^#.*}{};
s{\n##.*}{};
s{(?:^|\n)\s*\*}{}g;
s{\s+}{ }g;
print' < "$comment_body")
  
update_files
rm $comment_body
git add -u

Copy link
Contributor

@yao-msft yao-msft left a comment

Choose a reason for hiding this comment

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

:shipit:

@JohnMcPMS JohnMcPMS merged commit 90f1393 into microsoft:master Jul 21, 2022
@JohnMcPMS JohnMcPMS deleted the sql-err branch July 21, 2022 21:16
jontab added a commit to jontab/winget-cli that referenced this pull request Jul 21, 2022
commit d8e4fe4
Merge: 8aa5a4e 156282c
Author: Jonathan Abbott <jtabbott2001@gmail.com>
Date:   Thu Jul 21 15:22:30 2022 -0700

    Merge branch 'master' of https://github.com/microsoft/winget-cli into user/t-jabbott/powershell

commit 156282c
Author: AmirMS <104940545+AmelBawa-msft@users.noreply.github.com>
Date:   Thu Jul 21 14:31:32 2022 -0700

    Add in-process and out-of-process E2E tests (microsoft#2315)

commit 90f1393
Author: JohnMcPMS <johnmcp@microsoft.com>
Date:   Thu Jul 21 14:16:47 2022 -0700

    Move to using sqlite3_errmsg to extract a contextual error for SQLite failures (microsoft#2352)
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