Skip to content

Commit

Permalink
Fix unwanted stack trace on alr publish --tar with broken manifest (#…
Browse files Browse the repository at this point in the history
…1499)

* Avoid unhandled exception in `alr publish --tar`

Fixes #1214

Also unify a couple of error messages

* Update test to check this fix

* Self-review
  • Loading branch information
mosteo authored Nov 14, 2023
1 parent 88f17ab commit 88385f5
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 34 deletions.
84 changes: 55 additions & 29 deletions src/alire/alire-publish.adb
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,65 @@ package body Alire.Publish is
-- generating an error. E.g., if the user doesn't want to submit online
-- after successful manifest generation.

-----------------------
-- Check_Root_Status --
-----------------------

procedure Check_Root_Status (Path : Any_Path;
Root : Roots.Optional.Root;
Options : All_Options)
is
-- Path is supplied by the user and may not be a good path. Root has
-- been attempted to be detected at Path.
use all type Roots.Optional.States;

---------------
-- Full_Path --
---------------

function Full_Path (Path : Any_Path) return Any_Path
is (if Directories.Adirs.Exists (Path)
then Directories.Adirs.Full_Name (Path)
else Path);

begin
case Root.Status is
when Outside =>
if Options.Nonstandard_Manifest then
Trace.Debug ("Using non-standard manifest location: "
& Options.Manifest);
else
Raise_Checked_Error ("No Alire workspace found at "
& TTY.URL (Full_Path (Path)));
end if;
when Broken =>
Raise_Checked_Error
(Errors.Wrap
("Invalid metadata found at " & TTY.URL (Full_Path (Path)),
Root.Brokenness));
when Valid => null;
end case;
end Check_Root_Status;

---------------
-- Base_Path --
---------------
-- The workspace root path. To support out-of-alire packaging, this
-- defaults to the current directory when using a nonstandard manifest.
function Base_Path (This : Data) return Any_Path
is (if This.Options.Nonstandard_Manifest
then +This.Path
else Root.Current.Path);
is
begin
if This.Options.Nonstandard_Manifest then
return +This.Path;
else
declare
Root : constant Roots.Optional.Root := Alire.Root.Current;
begin
Check_Root_Status (+This.Path, Root, This.Options);
return Root.Value.Path;
end;
end if;
end Base_Path;

-----------------
-- Deploy_Path --
Expand Down Expand Up @@ -1010,37 +1060,12 @@ package body Alire.Publish is
is
Root : constant Roots.Optional.Root := Roots.Optional.Search_Root (Path);
Git : constant VCSs.Git.VCS := VCSs.Git.Handler;
use all type Roots.Optional.States;

Subdir : Unbounded_Relative_Path;
-- In case we are publishing a nested crate (monorepo), its relative
-- path in regard to the git worktree will be stored here by
-- Check_Nested_Crate.

-----------------------
-- Check_Root_Status --
-----------------------

procedure Check_Root_Status is
begin
case Root.Status is
when Outside =>
if Options.Nonstandard_Manifest then
Trace.Debug ("Using non-standard manifest location: "
& Options.Manifest);
else
Raise_Checked_Error ("No Alire workspace found at "
& TTY.URL (Path));
end if;
when Broken =>
Raise_Checked_Error
(Errors.Wrap
("Invalid metadata found at " & TTY.URL (Path),
Root.Brokenness));
when Valid => null;
end case;
end Check_Root_Status;

------------------------
-- Check_Nested_Crate --
------------------------
Expand Down Expand Up @@ -1078,7 +1103,8 @@ package body Alire.Publish is

begin

Check_Root_Status;
-- Early report and exit if there's any trouble with the supplied path
Check_Root_Status (Path, Root, Options);

declare
Root_Path : constant Absolute_Path :=
Expand Down
16 changes: 11 additions & 5 deletions testsuite/tests/publish/broken-manifest/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

from drivers.alr import run_alr, init_local_crate
from drivers.asserts import assert_match
from drivers.helpers import contents, content_of, init_git_repo, zip_dir
from shutil import copyfile, rmtree
from zipfile import ZipFile

import os
from shutil import rmtree


# Prepare a repo for publishing and break its manifest
Expand All @@ -21,4 +17,14 @@
p = run_alr("publish", force=True, complain_on_error=False)
assert_match(".*invalid syntax at.*alire\.toml.*", p.out)

# The same should happen when using the --tar option, and without backtrace
# that obscures the diagnostic, as this error is explicitly checked by Alire.
# This is a regression test for #1214.
p = run_alr("publish", "--tar", debug=False, force=True, complain_on_error=False)
assert_match("ERROR: Invalid metadata found at .*\n"
"ERROR: Failed to load alire.toml:\n"
"ERROR: Invalid TOML contents in file:\n"
"ERROR: invalid syntax at alire.toml:2:1\n",
p.out)

print('SUCCESS')

0 comments on commit 88385f5

Please sign in to comment.