@@ -3,7 +3,7 @@ use crossterm::{style::Stylize as _, tty::IsTty as _};
3
3
use futures:: FutureExt as _;
4
4
use num:: ToPrimitive as _;
5
5
use std:: { fmt:: Write as _, path:: PathBuf , sync:: Mutex , time:: Duration } ;
6
- use tangram_client:: { self as tg, Client } ;
6
+ use tangram_client:: { self as tg, Client , Handle as _ } ;
7
7
use tangram_either:: Either ;
8
8
use tangram_server:: Server ;
9
9
use tokio:: io:: AsyncWriteExt as _;
@@ -196,7 +196,7 @@ impl Cli {
196
196
Ok ( config) => config,
197
197
Err ( error) => {
198
198
eprintln ! ( "{} failed to read the config" , "error" . red( ) . bold( ) ) ;
199
- Cli :: print_error ( & error, None ) ;
199
+ Cli :: print_error ( & error, None , None ) ;
200
200
return 1 . into ( ) ;
201
201
} ,
202
202
} ;
@@ -278,7 +278,7 @@ impl Cli {
278
278
Ok ( ( ) ) => 0 . into ( ) ,
279
279
Err ( error) => {
280
280
eprintln ! ( "{} failed to run the command" , "error" . red( ) . bold( ) ) ;
281
- Cli :: print_error ( & error, cli. config . as_ref ( ) ) ;
281
+ Cli :: print_error ( & error, cli. config . as_ref ( ) , None ) ;
282
282
1 . into ( )
283
283
} ,
284
284
} ;
@@ -904,7 +904,7 @@ impl Cli {
904
904
Ok ( ( ) )
905
905
}
906
906
907
- fn print_error ( error : & tg:: Error , config : Option < & Config > ) {
907
+ fn print_error ( error : & tg:: Error , config : Option < & Config > , source_map : Option < & tg :: SourceMap > ) {
908
908
let options = config
909
909
. as_ref ( )
910
910
. and_then ( |config| config. advanced . as_ref ( ) )
@@ -919,6 +919,9 @@ impl Cli {
919
919
errors. reverse ( ) ;
920
920
}
921
921
for error in errors {
922
+ let error = source_map
923
+ . map ( |map| map. convert_error ( error. clone ( ) ) )
924
+ . unwrap_or_else ( || error. clone ( ) ) ;
922
925
let message = error. message . as_deref ( ) . unwrap_or ( "an error occurred" ) ;
923
926
eprintln ! ( "{} {message}" , "->" . red( ) ) ;
924
927
if let Some ( location) = & error. location {
@@ -946,7 +949,10 @@ impl Cli {
946
949
}
947
950
}
948
951
949
- fn print_diagnostic ( diagnostic : & tg:: Diagnostic ) {
952
+ fn print_diagnostic ( diagnostic : & tg:: Diagnostic , source_map : Option < & tg:: SourceMap > ) {
953
+ let diagnostic = source_map
954
+ . map ( |map| map. convert_diagnostic ( diagnostic. clone ( ) ) )
955
+ . unwrap_or_else ( || diagnostic. clone ( ) ) ;
950
956
let title = match diagnostic. severity {
951
957
tg:: diagnostic:: Severity :: Error => "error" . red ( ) . bold ( ) ,
952
958
tg:: diagnostic:: Severity :: Warning => "warning" . yellow ( ) . bold ( ) ,
@@ -1020,7 +1026,7 @@ impl Cli {
1020
1026
async fn get_reference (
1021
1027
& self ,
1022
1028
reference : & tg:: Reference ,
1023
- ) -> tg:: Result < tg:: Referent < Either < tg:: Build , tg:: Object > > > {
1029
+ ) -> tg:: Result < ( tg:: Referent < Either < tg:: Build , tg:: Object > > , Option < PathBuf > ) > {
1024
1030
let handle = self . handle ( ) . await ?;
1025
1031
let mut item = reference. item ( ) . clone ( ) ;
1026
1032
let mut options = reference. options ( ) . cloned ( ) ;
@@ -1033,8 +1039,22 @@ impl Cli {
1033
1039
. map_err ( |source| tg:: error!( !source, "failed to get the absolute path" ) ) ?;
1034
1040
}
1035
1041
let reference = tg:: Reference :: with_item_and_options ( & item, options. as_ref ( ) ) ;
1036
- let referent = reference. get ( & handle) . await ?;
1037
- Ok ( referent)
1042
+ let output = handle
1043
+ . try_get_reference ( & reference)
1044
+ . await ?
1045
+ . ok_or_else ( || tg:: error!( "failed to get reference" ) ) ?;
1046
+ let item = output
1047
+ . referent
1048
+ . item
1049
+ . map_left ( tg:: Build :: with_id)
1050
+ . map_right ( tg:: Object :: with_id) ;
1051
+ let referent = tg:: Referent {
1052
+ item,
1053
+ path : output. referent . path ,
1054
+ subpath : output. referent . subpath ,
1055
+ tag : output. referent . tag ,
1056
+ } ;
1057
+ Ok ( ( referent, output. lockfile ) )
1038
1058
}
1039
1059
1040
1060
/// Initialize V8.
0 commit comments