Use custom types and messages for errors

This commit is contained in:
Chris Roberts 2018-01-02 14:36:28 -08:00
parent 30dcd9a7e5
commit 3eeff59329
3 changed files with 25 additions and 2 deletions

View File

@ -64,7 +64,10 @@ module VagrantPlugins
# Check if this name is already in use
if share_info = current_shares[data[:smb_id]]
if !hostpath.empty? && share_info["Path"].downcase != hostpath.downcase
raise "share in use with different path"
raise SyncedFolderSMB::Errors::SMBNameError,
path: hostpath,
existing_path: share_info["Path"],
name: data[:smb_id]
end
@@logger.info("skip creation of existing share name=#{name} id=#{data[:smb_id]}")
next
@ -98,7 +101,7 @@ module VagrantPlugins
def self.existing_shares
result = Vagrant::Util::PowerShell.execute_cmd("Get-SmbShare|Format-List")
if result.nil?
raise "failed to get existing shares"
raise SyncedFolderSMB::Errors::SMBListFailed
end
shares = {}
name = nil

View File

@ -18,6 +18,14 @@ module VagrantPlugins
error_key(:credentials_missing)
end
class SMBListFailed < SMBError
error_key(:list_failed)
end
class SMBNameError < SMBError
error_key(:name_error)
end
class DefineShareFailed < SMBError
error_key(:define_share_failed)
end

View File

@ -55,6 +55,18 @@ en:
Stderr: %{stderr}
Stdout: %{stdout}
name_error: |-
Vagrant is unable to setup a requested SMB share. An SMB share already
exists with the given name.
Share name: %{name}
Current path: %{existing_path}
Requested path: %{path}
list_failed: |-
Vagrant failed to generate a list of local SMB shares. Please try
running the command again.
no_routable_host_addr: |-
We couldn't detect an IP address that was routable to this
machine from the guest machine! Please verify networking is properly