Skip to content

Commit 3e1226d

Browse files
committed
Introduce reportWarnRaw functions
1 parent 166f5b7 commit 3e1226d

File tree

7 files changed

+32
-16
lines changed

7 files changed

+32
-16
lines changed

cmd/goal/account.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ var newMultisigCmd = &cobra.Command{
396396
}
397397
}
398398
if duplicatesDetected {
399-
reportWarnln(warnMultisigDuplicatesDetected)
399+
reportWarnRawln(warnMultisigDuplicatesDetected)
400400
}
401401
// Generate a new address in the default wallet
402402
addr, err := client.CreateMultisigAccount(wh, threshold, args)
@@ -1369,7 +1369,7 @@ var importRootKeysCmd = &cobra.Command{
13691369
if err != nil {
13701370
// If error is 'like' "key already exists", treat as warning and not an error
13711371
if strings.Contains(err.Error(), "key already exists") {
1372-
reportWarnf("Warning: "+errorRequestFail, err.Error()+"\n > Key File: "+filename)
1372+
reportWarnf(errorRequestFail, err.Error()+"\n > Key File: "+filename)
13731373
} else {
13741374
reportErrorf(errorRequestFail, err)
13751375
}

cmd/goal/application.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ var createAppCmd = &cobra.Command{
448448

449449
switch onCompletionEnum {
450450
case transactions.CloseOutOC, transactions.ClearStateOC:
451-
reportWarnf("Warning: '--on-completion %s' may be ill-formed for 'goal app create'", onCompletion)
451+
reportWarnf("'--on-completion %s' may be ill-formed for 'goal app create'", onCompletion)
452452
}
453453

454454
tx, err := client.MakeUnsignedAppCreateTx(onCompletionEnum, approvalProg, clearProg, globalSchema, localSchema, appArgs, appAccounts, foreignApps, foreignAssets, extraPages)
@@ -1204,7 +1204,7 @@ var methodAppCmd = &cobra.Command{
12041204

12051205
switch onCompletionEnum {
12061206
case transactions.CloseOutOC, transactions.ClearStateOC:
1207-
reportWarnf("Warning: '--on-completion %s' may be ill-formed for use with --create", onCompletion)
1207+
reportWarnf("'--on-completion %s' may be ill-formed for use with --create", onCompletion)
12081208
}
12091209
} else {
12101210
if appIdx == 0 {

cmd/goal/asset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ var assetCmd = &cobra.Command{
141141

142142
func lookupAssetID(cmd *cobra.Command, creator string, client libgoal.Client) {
143143
if cmd.Flags().Changed("asset") {
144-
reportWarnln("Warning: The [--asset] flag is deprecated and will be removed in a future release, use [--unitname] instead.")
144+
reportWarnln("The [--asset] flag is deprecated and will be removed in a future release, use [--unitname] instead.")
145145
}
146146

147147
if cmd.Flags().Changed("asset") && cmd.Flags().Changed("unitname") {

cmd/goal/clerk.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ var sendCmd = &cobra.Command{
469469

470470
// Append the signer since it's a rekey txn
471471
if basics.Address(addr) == stx.Txn.Sender {
472-
reportWarnln("Warning:" + rekeySenderTargetSameError)
472+
reportWarnln(rekeySenderTargetSameError)
473473
}
474474
stx.AuthAddr = basics.Address(addr)
475475
}
@@ -557,7 +557,7 @@ var rawsendCmd = &cobra.Command{
557557
for _, txn := range txgroup {
558558
txnErrors[txn.ID()] = err.Error()
559559
}
560-
reportWarnf("Warning: "+errorBroadcastingTX, err)
560+
reportWarnf(errorBroadcastingTX, err)
561561
continue
562562
}
563563

@@ -584,7 +584,7 @@ var rawsendCmd = &cobra.Command{
584584
txn, err := client.PendingTransactionInformation(txidStr)
585585
if err != nil {
586586
txnErrors[txid] = err.Error()
587-
reportWarnf("Warning: "+errorRequestFail, err)
587+
reportWarnf(errorRequestFail, err)
588588
continue
589589
}
590590

@@ -595,7 +595,7 @@ var rawsendCmd = &cobra.Command{
595595

596596
if txn.PoolError != "" {
597597
txnErrors[txid] = txn.PoolError
598-
reportWarnf("Warning: "+txPoolError, txidStr, txn.PoolError)
598+
reportWarnf(txPoolError, txidStr, txn.PoolError)
599599
continue
600600
}
601601

@@ -950,13 +950,13 @@ func assembleFile(fname string, printWarnings bool) (program []byte) {
950950

951951
if printWarnings && len(ops.Warnings) != 0 {
952952
for _, warning := range ops.Warnings {
953-
reportWarnln(warning.Error())
953+
reportWarnRawln(warning.Error())
954954
}
955955
plural := "s"
956956
if len(ops.Warnings) == 1 {
957957
plural = ""
958958
}
959-
reportWarnf("%d warning%s", len(ops.Warnings), plural)
959+
reportWarnRawf("%d warning%s", len(ops.Warnings), plural)
960960
}
961961

962962
return ops.Program

cmd/goal/commands.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,9 @@ func reportInfof(format string, args ...interface{}) {
517517
reportInfoln(fmt.Sprintf(format, args...))
518518
}
519519

520-
func reportWarnln(args ...interface{}) {
520+
// reportWarnRawln prints a warning message to stderr. Only use this function if that warning
521+
// message already indicates that it's a warning. Otherwise, use reportWarnln
522+
func reportWarnRawln(args ...interface{}) {
521523
for _, line := range strings.Split(fmt.Sprint(args...), "\n") {
522524
printable, line := unicodePrintable(line)
523525
if !printable {
@@ -528,6 +530,20 @@ func reportWarnln(args ...interface{}) {
528530
}
529531
}
530532

533+
// reportWarnRawf prints a warning message to stderr. Only use this function if that warning message
534+
// already indicates that it's a warning. Otherwise, use reportWarnf
535+
func reportWarnRawf(format string, args ...interface{}) {
536+
reportWarnRawln(fmt.Sprintf(format, args...))
537+
}
538+
539+
// reportWarnln prints a warning message to stderr. The message will be prefixed with "Warning: ".
540+
// If you don't want this prefix, use reportWarnRawln
541+
func reportWarnln(args ...interface{}) {
542+
reportWarnRawf("Warning: %s", args...)
543+
}
544+
545+
// reportWarnf prints a warning message to stderr. The message will be prefixed with "Warning: ". If
546+
// you don't want this prefix, use reportWarnRawf
531547
func reportWarnf(format string, args ...interface{}) {
532548
reportWarnln(fmt.Sprintf(format, args...))
533549
}

cmd/goal/interact.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ var appExecuteCmd = &cobra.Command{
574574
if appIdx == 0 {
575575
switch onCompletion {
576576
case transactions.CloseOutOC, transactions.ClearStateOC:
577-
reportWarnf("Warning: OnCompletion %s may be ill-formed when creating an application", onCompletion)
577+
reportWarnf("OnCompletion %s may be ill-formed when creating an application", onCompletion)
578578
}
579579
}
580580

cmd/goal/logging.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var loggingCmd = &cobra.Command{
5050
Long: `Enable/disable and configure Algorand remote logging.`,
5151
Args: validateNoPosArgsFn,
5252
Run: func(cmd *cobra.Command, _ []string) {
53-
fmt.Fprintf(os.Stderr, "Warning: `goal logging` deprecated, use `diagcfg telemetry status`\n")
53+
reportWarnln("`goal logging` deprecated, use `diagcfg telemetry status`")
5454
dataDir := ensureSingleDataDir()
5555
cfg, err := logging.EnsureTelemetryConfig(&dataDir, "")
5656

@@ -72,7 +72,7 @@ var enableCmd = &cobra.Command{
7272
Long: `This will turn on remote logging. The "friendly name" for the node, used by logging, will be determined by -n nodename.`,
7373
Args: validateNoPosArgsFn,
7474
Run: func(cmd *cobra.Command, _ []string) {
75-
fmt.Fprintf(os.Stderr, "Warning: `goal logging enable` deprecated, use `diagcfg telemetry enable`\n")
75+
reportWarnln("`goal logging enable` deprecated, use `diagcfg telemetry enable`")
7676
dataDir := ensureSingleDataDir()
7777
cfg, err := logging.EnsureTelemetryConfig(&dataDir, "")
7878
if err != nil {
@@ -93,7 +93,7 @@ var disableCmd = &cobra.Command{
9393
Short: "Disable Algorand remote logging",
9494
Args: validateNoPosArgsFn,
9595
Run: func(cmd *cobra.Command, _ []string) {
96-
fmt.Fprintf(os.Stderr, "Warning: `goal logging disable` deprecated, use `diagcfg telemetry disable`\n")
96+
reportWarnf("`goal logging disable` deprecated, use `diagcfg telemetry disable`")
9797
dataDir := ensureSingleDataDir()
9898
cfg, err := logging.EnsureTelemetryConfig(&dataDir, "")
9999

0 commit comments

Comments
 (0)