PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/spotify/error.go

https://github.com/tomnewton/go-libspotify
Go | 145 lines | 49 code | 40 blank | 56 comment | 2 complexity | df3635a3827a174c7fd2d72cacecbee1 MD5 | raw file
Possible License(s): Apache-2.0
  1. // Copyright 2013 Örjan Persson
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package spotify
  15. /*
  16. #cgo pkg-config: libspotify
  17. #include <libspotify/api.h>
  18. */
  19. import "C"
  20. type Error C.sp_error
  21. func (e Error) Error() string {
  22. return C.GoString(C.sp_error_message(C.sp_error(e)))
  23. }
  24. const (
  25. // The library version targeted does not match the one you claim you
  26. // support
  27. ErrBadAPIVersion Error = Error(C.SP_ERROR_BAD_API_VERSION)
  28. // Initialization of library failed - are cache locations etc. valid?
  29. ErrAPIInitializationFailed = Error(C.SP_ERROR_API_INITIALIZATION_FAILED)
  30. // The track specified for playing cannot be played
  31. ErrTrackNotPlayable = Error(C.SP_ERROR_TRACK_NOT_PLAYABLE)
  32. // The application key is invalid
  33. ErrBadApplicationKey = Error(C.SP_ERROR_BAD_APPLICATION_KEY)
  34. // Login failed because of bad username and/or password
  35. ErrBadUsernameOrPassword = Error(C.SP_ERROR_BAD_USERNAME_OR_PASSWORD)
  36. // The specified username is banned
  37. ErrUserBanned = Error(C.SP_ERROR_USER_BANNED)
  38. // Cannot connect to the Spotify backend system
  39. ErrUnableToContactServer = Error(C.SP_ERROR_UNABLE_TO_CONTACT_SERVER)
  40. // Client is too old, library will need to be updated
  41. ErrClientTooOld = Error(C.SP_ERROR_CLIENT_TOO_OLD)
  42. // Some other error occurred, and it is permanent (e.g. trying to relogin
  43. // will not help)
  44. ErrOtherPermanent = Error(C.SP_ERROR_OTHER_PERMANENT)
  45. // The user agent string is invalid or too long
  46. ErrBadUserAgent = Error(C.SP_ERROR_BAD_USER_AGENT)
  47. // No valid callback registered to handle events
  48. ErrMissingCallback = Error(C.SP_ERROR_MISSING_CALLBACK)
  49. // Input data was either missing or invalid
  50. ErrInvalidIndata = Error(C.SP_ERROR_INVALID_INDATA)
  51. // Index out of range
  52. ErrIndexOutOfRange = Error(C.SP_ERROR_INDEX_OUT_OF_RANGE)
  53. // The specified user needs a premium account
  54. ErrUserNeedsPremium = Error(C.SP_ERROR_USER_NEEDS_PREMIUM)
  55. // A transient error occurred.
  56. ErrOtherTransient = Error(C.SP_ERROR_OTHER_TRANSIENT)
  57. // The resource is currently loading
  58. ErrIsLoading = Error(C.SP_ERROR_IS_LOADING)
  59. // Could not find any suitable stream to play
  60. ErrNoStreamAvailable = Error(C.SP_ERROR_NO_STREAM_AVAILABLE)
  61. // Requested operation is not allowed
  62. ErrPermissionDenied = Error(C.SP_ERROR_PERMISSION_DENIED)
  63. // Target inbox is full
  64. ErrInboxIsFull = Error(C.SP_ERROR_INBOX_IS_FULL)
  65. // Cache is not enabled
  66. ErrNoCache = Error(C.SP_ERROR_NO_CACHE)
  67. // Requested user does not exist
  68. ErrNoSuchUser = Error(C.SP_ERROR_NO_SUCH_USER)
  69. // No credentials are stored
  70. ErrNoCredentials = Error(C.SP_ERROR_NO_CREDENTIALS)
  71. // Network disabled
  72. ErrNetworkDisabled = Error(C.SP_ERROR_NETWORK_DISABLED)
  73. // Invalid device ID
  74. ErrInvalidDeviceId = Error(C.SP_ERROR_INVALID_DEVICE_ID)
  75. // Unable to open trace file
  76. ErrCantOpenTraceFile = Error(C.SP_ERROR_CANT_OPEN_TRACE_FILE)
  77. // This application is no longer allowed to use the Spotify service
  78. ErrApplicationBanned = Error(C.SP_ERROR_APPLICATION_BANNED)
  79. // Reached the device limit for number of tracks to download
  80. ErrOfflineTooManyTracks = Error(C.SP_ERROR_OFFLINE_TOO_MANY_TRACKS)
  81. // Disk cache is full so no more tracks can be downloaded to offline mode
  82. ErrOfflineDiskCache = Error(C.SP_ERROR_OFFLINE_DISK_CACHE)
  83. // Offline key has expired, the user needs to go online again
  84. ErrOfflineExpired = Error(C.SP_ERROR_OFFLINE_EXPIRED)
  85. // This user is not allowed to use offline mode
  86. ErrOfflineNotAllowed = Error(C.SP_ERROR_OFFLINE_NOT_ALLOWED)
  87. // The license for this device has been lost. Most likely because the user
  88. // used offline on three other device
  89. ErrOfflineLicenseLost = Error(C.SP_ERROR_OFFLINE_LICENSE_LOST)
  90. // The Spotify license server does not respond correctly
  91. ErrOfflineLicenseError = Error(C.SP_ERROR_OFFLINE_LICENSE_ERROR)
  92. // A LastFM scrobble authentication error has occurred
  93. ErrLastFMAuthError = Error(C.SP_ERROR_LASTFM_AUTH_ERROR)
  94. // An invalid argument was specified
  95. ErrInvalidArgument = Error(C.SP_ERROR_INVALID_ARGUMENT)
  96. // An operating system error
  97. ErrSystemFailure = Error(C.SP_ERROR_SYSTEM_FAILURE)
  98. )
  99. // spError converts an error from libspotify into a Go error.
  100. func spError(err C.sp_error) error {
  101. if err != C.SP_ERROR_OK {
  102. return Error(err)
  103. }
  104. return nil
  105. }