boxstarter icon indicating copy to clipboard operation
boxstarter copied to clipboard

Boxstarter should report how many packages failed to install

Open mwallner opened this issue 5 years ago • 7 comments

What You Are Seeing?

Invoke-ChocolateyBoxstarter doesn't provide any information if something failed along the way.

What is Expected?

(in case of 'no-reboots-required') either $lastexitcode or a try{ .. } catch { ...} should be sufficient to check if something went wrong.

How Did You Get This To Happen? (Steps to Reproduce)

using Boxstarter.bat

C:\myboxstarter\Boxstarter.bat pkg_does_not_exist
echo %errorlevel%

I'd suggest something like

if($chocoErrors -gt 0){
    $lastexitcode = $chocoErrors
    throw "got $chocoErrors Chocolatey errors"
}

here, right after the foreach($packageName in $packageNames){ ... }

mwallner avatar Jul 22 '19 13:07 mwallner

If you used the throw statement it would stop the rest of Boxstarter. What we need to decide is if not being able to install packages is something that is a critical error or not. It may also come into the realms of #296 ?

What might be nice is if we have somewhere we can log issues / warnings / errors that the end user should know about and then, when everything is done, display them to the user? Something like a Add-BoxstarterIssue and then a Write-BoxstarterIssue (I'm just thinking out loud just now).

pauby avatar Jul 22 '19 14:07 pauby

I was also thinking about #296, in contrast to the (initial) suggested change there, this would actually try to install all packages, before setting $lastexitcode to the number of failed choco installs.

mwallner avatar Jul 22 '19 14:07 mwallner

Rather then the number of failed installs (does it matter how many?) you could just exit 1 or 0?

I'm not against the idea. I think that:

  1. Maybe we should turn it into a copy larger feature (such as recording the errors like I suggested above);

  2. Would be interested in seeing the detail on how it's done;

pauby avatar Jul 22 '19 14:07 pauby

I actually don't care how many installs failed, the thing is that, with a current version of Boxstarter, it is hard to get some useful return/exit code that tells you if something went wrong or not.

I do like your suggestion with the Add-BoxstarterIssue, followed by a final Get-BoxstarterIssues | % { Write-BoxstarterIssue $_ }, but also would need to put something like

if ((Get-BoxstarterIssues).Count -gt 0) { 
  exit 1 
}

somewhere at the end of the default Boxstarter procedure.

(it should not matter, if you call Invoke-ChocolateyBoxstarter pkg1,pkg2 or Boxstarter.bat pkg1,pkg2)

mwallner avatar Jul 22 '19 20:07 mwallner

Just revisited this. Note: when this is being implemented, take sure to note this:

If you used the throw statement it would stop the rest of Boxstarter.

meaning: reporting of the install error and setting of the return code must happen last, after Boxstarter cleanup-phase (UAC, Win-Update Settings etc. need to be restored!!)

mwallner avatar Aug 30 '19 15:08 mwallner

@mwallner is this not fixed with PR #296 / #402 ?

pauby avatar Oct 19 '20 09:10 pauby

Short answer: no, this issue is something different as we're aiming to provide some feedback on which packages were installed successfully and which failed - after the Boxstarter procedure finished. (without the early-stopping bits)

mwallner avatar Oct 19 '20 10:10 mwallner