1// Copyright 2015 The Gogs Authors. All rights reserved. 2// Copyright 2019 The Gitea Authors. All rights reserved. 3// Use of this source code is governed by a MIT-style 4// license that can be found in the LICENSE file. 5 6package models 7 8import ( 9 "fmt" 10 11 "code.gitea.io/gitea/models/perm" 12 repo_model "code.gitea.io/gitea/models/repo" 13 "code.gitea.io/gitea/modules/git" 14) 15 16// ErrNotExist represents a non-exist error. 17type ErrNotExist struct { 18 ID int64 19} 20 21// IsErrNotExist checks if an error is an ErrNotExist 22func IsErrNotExist(err error) bool { 23 _, ok := err.(ErrNotExist) 24 return ok 25} 26 27func (err ErrNotExist) Error() string { 28 return fmt.Sprintf("record does not exist [id: %d]", err.ID) 29} 30 31// ErrUserOwnRepos represents a "UserOwnRepos" kind of error. 32type ErrUserOwnRepos struct { 33 UID int64 34} 35 36// IsErrUserOwnRepos checks if an error is a ErrUserOwnRepos. 37func IsErrUserOwnRepos(err error) bool { 38 _, ok := err.(ErrUserOwnRepos) 39 return ok 40} 41 42func (err ErrUserOwnRepos) Error() string { 43 return fmt.Sprintf("user still has ownership of repositories [uid: %d]", err.UID) 44} 45 46// ErrUserHasOrgs represents a "UserHasOrgs" kind of error. 47type ErrUserHasOrgs struct { 48 UID int64 49} 50 51// IsErrUserHasOrgs checks if an error is a ErrUserHasOrgs. 52func IsErrUserHasOrgs(err error) bool { 53 _, ok := err.(ErrUserHasOrgs) 54 return ok 55} 56 57func (err ErrUserHasOrgs) Error() string { 58 return fmt.Sprintf("user still has membership of organizations [uid: %d]", err.UID) 59} 60 61// ErrUserNotAllowedCreateOrg represents a "UserNotAllowedCreateOrg" kind of error. 62type ErrUserNotAllowedCreateOrg struct{} 63 64// IsErrUserNotAllowedCreateOrg checks if an error is an ErrUserNotAllowedCreateOrg. 65func IsErrUserNotAllowedCreateOrg(err error) bool { 66 _, ok := err.(ErrUserNotAllowedCreateOrg) 67 return ok 68} 69 70func (err ErrUserNotAllowedCreateOrg) Error() string { 71 return "user is not allowed to create organizations" 72} 73 74// __ __.__ __ .__ 75// / \ / \__| | _|__| 76// \ \/\/ / | |/ / | 77// \ /| | <| | 78// \__/\ / |__|__|_ \__| 79// \/ \/ 80 81// ErrWikiAlreadyExist represents a "WikiAlreadyExist" kind of error. 82type ErrWikiAlreadyExist struct { 83 Title string 84} 85 86// IsErrWikiAlreadyExist checks if an error is an ErrWikiAlreadyExist. 87func IsErrWikiAlreadyExist(err error) bool { 88 _, ok := err.(ErrWikiAlreadyExist) 89 return ok 90} 91 92func (err ErrWikiAlreadyExist) Error() string { 93 return fmt.Sprintf("wiki page already exists [title: %s]", err.Title) 94} 95 96// ErrWikiReservedName represents a reserved name error. 97type ErrWikiReservedName struct { 98 Title string 99} 100 101// IsErrWikiReservedName checks if an error is an ErrWikiReservedName. 102func IsErrWikiReservedName(err error) bool { 103 _, ok := err.(ErrWikiReservedName) 104 return ok 105} 106 107func (err ErrWikiReservedName) Error() string { 108 return fmt.Sprintf("wiki title is reserved: %s", err.Title) 109} 110 111// ErrWikiInvalidFileName represents an invalid wiki file name. 112type ErrWikiInvalidFileName struct { 113 FileName string 114} 115 116// IsErrWikiInvalidFileName checks if an error is an ErrWikiInvalidFileName. 117func IsErrWikiInvalidFileName(err error) bool { 118 _, ok := err.(ErrWikiInvalidFileName) 119 return ok 120} 121 122func (err ErrWikiInvalidFileName) Error() string { 123 return fmt.Sprintf("Invalid wiki filename: %s", err.FileName) 124} 125 126// _____ ___________ __ 127// / _ \ ____ ____ ____ ______ _____\__ ___/___ | | __ ____ ____ 128// / /_\ \_/ ___\/ ___\/ __ \ / ___// ___/ | | / _ \| |/ // __ \ / \ 129// / | \ \__\ \__\ ___/ \___ \ \___ \ | |( <_> ) <\ ___/| | \ 130// \____|__ /\___ >___ >___ >____ >____ > |____| \____/|__|_ \\___ >___| / 131// \/ \/ \/ \/ \/ \/ \/ \/ \/ 132 133// ErrAccessTokenNotExist represents a "AccessTokenNotExist" kind of error. 134type ErrAccessTokenNotExist struct { 135 Token string 136} 137 138// IsErrAccessTokenNotExist checks if an error is a ErrAccessTokenNotExist. 139func IsErrAccessTokenNotExist(err error) bool { 140 _, ok := err.(ErrAccessTokenNotExist) 141 return ok 142} 143 144func (err ErrAccessTokenNotExist) Error() string { 145 return fmt.Sprintf("access token does not exist [sha: %s]", err.Token) 146} 147 148// ErrAccessTokenEmpty represents a "AccessTokenEmpty" kind of error. 149type ErrAccessTokenEmpty struct{} 150 151// IsErrAccessTokenEmpty checks if an error is a ErrAccessTokenEmpty. 152func IsErrAccessTokenEmpty(err error) bool { 153 _, ok := err.(ErrAccessTokenEmpty) 154 return ok 155} 156 157func (err ErrAccessTokenEmpty) Error() string { 158 return "access token is empty" 159} 160 161// ________ .__ __ .__ 162// \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____ 163// / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \ 164// / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \ 165// \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| / 166// \/ /_____/ \/ \/ \/ \/ \/ 167 168// ErrOrgNotExist represents a "OrgNotExist" kind of error. 169type ErrOrgNotExist struct { 170 ID int64 171 Name string 172} 173 174// IsErrOrgNotExist checks if an error is a ErrOrgNotExist. 175func IsErrOrgNotExist(err error) bool { 176 _, ok := err.(ErrOrgNotExist) 177 return ok 178} 179 180func (err ErrOrgNotExist) Error() string { 181 return fmt.Sprintf("org does not exist [id: %d, name: %s]", err.ID, err.Name) 182} 183 184// ErrLastOrgOwner represents a "LastOrgOwner" kind of error. 185type ErrLastOrgOwner struct { 186 UID int64 187} 188 189// IsErrLastOrgOwner checks if an error is a ErrLastOrgOwner. 190func IsErrLastOrgOwner(err error) bool { 191 _, ok := err.(ErrLastOrgOwner) 192 return ok 193} 194 195func (err ErrLastOrgOwner) Error() string { 196 return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID) 197} 198 199//.____ ____________________ 200//| | \_ _____/ _____/ 201//| | | __) \_____ \ 202//| |___| \ / \ 203//|_______ \___ / /_______ / 204// \/ \/ \/ 205 206// ErrLFSLockNotExist represents a "LFSLockNotExist" kind of error. 207type ErrLFSLockNotExist struct { 208 ID int64 209 RepoID int64 210 Path string 211} 212 213// IsErrLFSLockNotExist checks if an error is a ErrLFSLockNotExist. 214func IsErrLFSLockNotExist(err error) bool { 215 _, ok := err.(ErrLFSLockNotExist) 216 return ok 217} 218 219func (err ErrLFSLockNotExist) Error() string { 220 return fmt.Sprintf("lfs lock does not exist [id: %d, rid: %d, path: %s]", err.ID, err.RepoID, err.Path) 221} 222 223// ErrLFSUnauthorizedAction represents a "LFSUnauthorizedAction" kind of error. 224type ErrLFSUnauthorizedAction struct { 225 RepoID int64 226 UserName string 227 Mode perm.AccessMode 228} 229 230// IsErrLFSUnauthorizedAction checks if an error is a ErrLFSUnauthorizedAction. 231func IsErrLFSUnauthorizedAction(err error) bool { 232 _, ok := err.(ErrLFSUnauthorizedAction) 233 return ok 234} 235 236func (err ErrLFSUnauthorizedAction) Error() string { 237 if err.Mode == perm.AccessModeWrite { 238 return fmt.Sprintf("User %s doesn't have write access for lfs lock [rid: %d]", err.UserName, err.RepoID) 239 } 240 return fmt.Sprintf("User %s doesn't have read access for lfs lock [rid: %d]", err.UserName, err.RepoID) 241} 242 243// ErrLFSLockAlreadyExist represents a "LFSLockAlreadyExist" kind of error. 244type ErrLFSLockAlreadyExist struct { 245 RepoID int64 246 Path string 247} 248 249// IsErrLFSLockAlreadyExist checks if an error is a ErrLFSLockAlreadyExist. 250func IsErrLFSLockAlreadyExist(err error) bool { 251 _, ok := err.(ErrLFSLockAlreadyExist) 252 return ok 253} 254 255func (err ErrLFSLockAlreadyExist) Error() string { 256 return fmt.Sprintf("lfs lock already exists [rid: %d, path: %s]", err.RepoID, err.Path) 257} 258 259// ErrLFSFileLocked represents a "LFSFileLocked" kind of error. 260type ErrLFSFileLocked struct { 261 RepoID int64 262 Path string 263 UserName string 264} 265 266// IsErrLFSFileLocked checks if an error is a ErrLFSFileLocked. 267func IsErrLFSFileLocked(err error) bool { 268 _, ok := err.(ErrLFSFileLocked) 269 return ok 270} 271 272func (err ErrLFSFileLocked) Error() string { 273 return fmt.Sprintf("File is lfs locked [repo: %d, locked by: %s, path: %s]", err.RepoID, err.UserName, err.Path) 274} 275 276// ErrNoPendingRepoTransfer is an error type for repositories without a pending 277// transfer request 278type ErrNoPendingRepoTransfer struct { 279 RepoID int64 280} 281 282func (e ErrNoPendingRepoTransfer) Error() string { 283 return fmt.Sprintf("repository doesn't have a pending transfer [repo_id: %d]", e.RepoID) 284} 285 286// IsErrNoPendingTransfer is an error type when a repository has no pending 287// transfers 288func IsErrNoPendingTransfer(err error) bool { 289 _, ok := err.(ErrNoPendingRepoTransfer) 290 return ok 291} 292 293// ErrRepoTransferInProgress represents the state of a repository that has an 294// ongoing transfer 295type ErrRepoTransferInProgress struct { 296 Uname string 297 Name string 298} 299 300// IsErrRepoTransferInProgress checks if an error is a ErrRepoTransferInProgress. 301func IsErrRepoTransferInProgress(err error) bool { 302 _, ok := err.(ErrRepoTransferInProgress) 303 return ok 304} 305 306func (err ErrRepoTransferInProgress) Error() string { 307 return fmt.Sprintf("repository is already being transferred [uname: %s, name: %s]", err.Uname, err.Name) 308} 309 310// ErrForkAlreadyExist represents a "ForkAlreadyExist" kind of error. 311type ErrForkAlreadyExist struct { 312 Uname string 313 RepoName string 314 ForkName string 315} 316 317// IsErrForkAlreadyExist checks if an error is an ErrForkAlreadyExist. 318func IsErrForkAlreadyExist(err error) bool { 319 _, ok := err.(ErrForkAlreadyExist) 320 return ok 321} 322 323func (err ErrForkAlreadyExist) Error() string { 324 return fmt.Sprintf("repository is already forked by user [uname: %s, repo path: %s, fork path: %s]", err.Uname, err.RepoName, err.ForkName) 325} 326 327// ErrInvalidCloneAddr represents a "InvalidCloneAddr" kind of error. 328type ErrInvalidCloneAddr struct { 329 Host string 330 IsURLError bool 331 IsInvalidPath bool 332 IsProtocolInvalid bool 333 IsPermissionDenied bool 334 LocalPath bool 335 NotResolvedIP bool 336} 337 338// IsErrInvalidCloneAddr checks if an error is a ErrInvalidCloneAddr. 339func IsErrInvalidCloneAddr(err error) bool { 340 _, ok := err.(*ErrInvalidCloneAddr) 341 return ok 342} 343 344func (err *ErrInvalidCloneAddr) Error() string { 345 if err.NotResolvedIP { 346 return fmt.Sprintf("migration/cloning from '%s' is not allowed: unknown hostname", err.Host) 347 } 348 if err.IsInvalidPath { 349 return fmt.Sprintf("migration/cloning from '%s' is not allowed: the provided path is invalid", err.Host) 350 } 351 if err.IsProtocolInvalid { 352 return fmt.Sprintf("migration/cloning from '%s' is not allowed: the provided url protocol is not allowed", err.Host) 353 } 354 if err.IsPermissionDenied { 355 return fmt.Sprintf("migration/cloning from '%s' is not allowed.", err.Host) 356 } 357 if err.IsURLError { 358 return fmt.Sprintf("migration/cloning from '%s' is not allowed: the provided url is invalid", err.Host) 359 } 360 361 return fmt.Sprintf("migration/cloning from '%s' is not allowed", err.Host) 362} 363 364// ErrUpdateTaskNotExist represents a "UpdateTaskNotExist" kind of error. 365type ErrUpdateTaskNotExist struct { 366 UUID string 367} 368 369// IsErrUpdateTaskNotExist checks if an error is a ErrUpdateTaskNotExist. 370func IsErrUpdateTaskNotExist(err error) bool { 371 _, ok := err.(ErrUpdateTaskNotExist) 372 return ok 373} 374 375func (err ErrUpdateTaskNotExist) Error() string { 376 return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID) 377} 378 379// ErrReleaseAlreadyExist represents a "ReleaseAlreadyExist" kind of error. 380type ErrReleaseAlreadyExist struct { 381 TagName string 382} 383 384// IsErrReleaseAlreadyExist checks if an error is a ErrReleaseAlreadyExist. 385func IsErrReleaseAlreadyExist(err error) bool { 386 _, ok := err.(ErrReleaseAlreadyExist) 387 return ok 388} 389 390func (err ErrReleaseAlreadyExist) Error() string { 391 return fmt.Sprintf("release tag already exist [tag_name: %s]", err.TagName) 392} 393 394// ErrReleaseNotExist represents a "ReleaseNotExist" kind of error. 395type ErrReleaseNotExist struct { 396 ID int64 397 TagName string 398} 399 400// IsErrReleaseNotExist checks if an error is a ErrReleaseNotExist. 401func IsErrReleaseNotExist(err error) bool { 402 _, ok := err.(ErrReleaseNotExist) 403 return ok 404} 405 406func (err ErrReleaseNotExist) Error() string { 407 return fmt.Sprintf("release tag does not exist [id: %d, tag_name: %s]", err.ID, err.TagName) 408} 409 410// ErrInvalidTagName represents a "InvalidTagName" kind of error. 411type ErrInvalidTagName struct { 412 TagName string 413} 414 415// IsErrInvalidTagName checks if an error is a ErrInvalidTagName. 416func IsErrInvalidTagName(err error) bool { 417 _, ok := err.(ErrInvalidTagName) 418 return ok 419} 420 421func (err ErrInvalidTagName) Error() string { 422 return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName) 423} 424 425// ErrProtectedTagName represents a "ProtectedTagName" kind of error. 426type ErrProtectedTagName struct { 427 TagName string 428} 429 430// IsErrProtectedTagName checks if an error is a ErrProtectedTagName. 431func IsErrProtectedTagName(err error) bool { 432 _, ok := err.(ErrProtectedTagName) 433 return ok 434} 435 436func (err ErrProtectedTagName) Error() string { 437 return fmt.Sprintf("release tag name is protected [tag_name: %s]", err.TagName) 438} 439 440// ErrRepoFileAlreadyExists represents a "RepoFileAlreadyExist" kind of error. 441type ErrRepoFileAlreadyExists struct { 442 Path string 443} 444 445// IsErrRepoFileAlreadyExists checks if an error is a ErrRepoFileAlreadyExists. 446func IsErrRepoFileAlreadyExists(err error) bool { 447 _, ok := err.(ErrRepoFileAlreadyExists) 448 return ok 449} 450 451func (err ErrRepoFileAlreadyExists) Error() string { 452 return fmt.Sprintf("repository file already exists [path: %s]", err.Path) 453} 454 455// ErrRepoFileDoesNotExist represents a "RepoFileDoesNotExist" kind of error. 456type ErrRepoFileDoesNotExist struct { 457 Path string 458 Name string 459} 460 461// IsErrRepoFileDoesNotExist checks if an error is a ErrRepoDoesNotExist. 462func IsErrRepoFileDoesNotExist(err error) bool { 463 _, ok := err.(ErrRepoFileDoesNotExist) 464 return ok 465} 466 467func (err ErrRepoFileDoesNotExist) Error() string { 468 return fmt.Sprintf("repository file does not exist [path: %s]", err.Path) 469} 470 471// ErrFilenameInvalid represents a "FilenameInvalid" kind of error. 472type ErrFilenameInvalid struct { 473 Path string 474} 475 476// IsErrFilenameInvalid checks if an error is an ErrFilenameInvalid. 477func IsErrFilenameInvalid(err error) bool { 478 _, ok := err.(ErrFilenameInvalid) 479 return ok 480} 481 482func (err ErrFilenameInvalid) Error() string { 483 return fmt.Sprintf("path contains a malformed path component [path: %s]", err.Path) 484} 485 486// ErrUserCannotCommit represents "UserCannotCommit" kind of error. 487type ErrUserCannotCommit struct { 488 UserName string 489} 490 491// IsErrUserCannotCommit checks if an error is an ErrUserCannotCommit. 492func IsErrUserCannotCommit(err error) bool { 493 _, ok := err.(ErrUserCannotCommit) 494 return ok 495} 496 497func (err ErrUserCannotCommit) Error() string { 498 return fmt.Sprintf("user cannot commit to repo [user: %s]", err.UserName) 499} 500 501// ErrFilePathInvalid represents a "FilePathInvalid" kind of error. 502type ErrFilePathInvalid struct { 503 Message string 504 Path string 505 Name string 506 Type git.EntryMode 507} 508 509// IsErrFilePathInvalid checks if an error is an ErrFilePathInvalid. 510func IsErrFilePathInvalid(err error) bool { 511 _, ok := err.(ErrFilePathInvalid) 512 return ok 513} 514 515func (err ErrFilePathInvalid) Error() string { 516 if err.Message != "" { 517 return err.Message 518 } 519 return fmt.Sprintf("path is invalid [path: %s]", err.Path) 520} 521 522// ErrFilePathProtected represents a "FilePathProtected" kind of error. 523type ErrFilePathProtected struct { 524 Message string 525 Path string 526} 527 528// IsErrFilePathProtected checks if an error is an ErrFilePathProtected. 529func IsErrFilePathProtected(err error) bool { 530 _, ok := err.(ErrFilePathProtected) 531 return ok 532} 533 534func (err ErrFilePathProtected) Error() string { 535 if err.Message != "" { 536 return err.Message 537 } 538 return fmt.Sprintf("path is protected and can not be changed [path: %s]", err.Path) 539} 540 541// ErrUserDoesNotHaveAccessToRepo represets an error where the user doesn't has access to a given repo. 542type ErrUserDoesNotHaveAccessToRepo struct { 543 UserID int64 544 RepoName string 545} 546 547// IsErrUserDoesNotHaveAccessToRepo checks if an error is a ErrRepoFileAlreadyExists. 548func IsErrUserDoesNotHaveAccessToRepo(err error) bool { 549 _, ok := err.(ErrUserDoesNotHaveAccessToRepo) 550 return ok 551} 552 553func (err ErrUserDoesNotHaveAccessToRepo) Error() string { 554 return fmt.Sprintf("user doesn't have access to repo [user_id: %d, repo_name: %s]", err.UserID, err.RepoName) 555} 556 557// __________ .__ 558// \______ \____________ ____ ____ | |__ 559// | | _/\_ __ \__ \ / \_/ ___\| | \ 560// | | \ | | \// __ \| | \ \___| Y \ 561// |______ / |__| (____ /___| /\___ >___| / 562// \/ \/ \/ \/ \/ 563 564// ErrBranchDoesNotExist represents an error that branch with such name does not exist. 565type ErrBranchDoesNotExist struct { 566 BranchName string 567} 568 569// IsErrBranchDoesNotExist checks if an error is an ErrBranchDoesNotExist. 570func IsErrBranchDoesNotExist(err error) bool { 571 _, ok := err.(ErrBranchDoesNotExist) 572 return ok 573} 574 575func (err ErrBranchDoesNotExist) Error() string { 576 return fmt.Sprintf("branch does not exist [name: %s]", err.BranchName) 577} 578 579// ErrBranchAlreadyExists represents an error that branch with such name already exists. 580type ErrBranchAlreadyExists struct { 581 BranchName string 582} 583 584// IsErrBranchAlreadyExists checks if an error is an ErrBranchAlreadyExists. 585func IsErrBranchAlreadyExists(err error) bool { 586 _, ok := err.(ErrBranchAlreadyExists) 587 return ok 588} 589 590func (err ErrBranchAlreadyExists) Error() string { 591 return fmt.Sprintf("branch already exists [name: %s]", err.BranchName) 592} 593 594// ErrBranchNameConflict represents an error that branch name conflicts with other branch. 595type ErrBranchNameConflict struct { 596 BranchName string 597} 598 599// IsErrBranchNameConflict checks if an error is an ErrBranchNameConflict. 600func IsErrBranchNameConflict(err error) bool { 601 _, ok := err.(ErrBranchNameConflict) 602 return ok 603} 604 605func (err ErrBranchNameConflict) Error() string { 606 return fmt.Sprintf("branch conflicts with existing branch [name: %s]", err.BranchName) 607} 608 609// ErrBranchesEqual represents an error that branch name conflicts with other branch. 610type ErrBranchesEqual struct { 611 BaseBranchName string 612 HeadBranchName string 613} 614 615// IsErrBranchesEqual checks if an error is an ErrBranchesEqual. 616func IsErrBranchesEqual(err error) bool { 617 _, ok := err.(ErrBranchesEqual) 618 return ok 619} 620 621func (err ErrBranchesEqual) Error() string { 622 return fmt.Sprintf("branches are equal [head: %sm base: %s]", err.HeadBranchName, err.BaseBranchName) 623} 624 625// ErrNotAllowedToMerge represents an error that a branch is protected and the current user is not allowed to modify it. 626type ErrNotAllowedToMerge struct { 627 Reason string 628} 629 630// IsErrNotAllowedToMerge checks if an error is an ErrNotAllowedToMerge. 631func IsErrNotAllowedToMerge(err error) bool { 632 _, ok := err.(ErrNotAllowedToMerge) 633 return ok 634} 635 636func (err ErrNotAllowedToMerge) Error() string { 637 return fmt.Sprintf("not allowed to merge [reason: %s]", err.Reason) 638} 639 640// ErrTagAlreadyExists represents an error that tag with such name already exists. 641type ErrTagAlreadyExists struct { 642 TagName string 643} 644 645// IsErrTagAlreadyExists checks if an error is an ErrTagAlreadyExists. 646func IsErrTagAlreadyExists(err error) bool { 647 _, ok := err.(ErrTagAlreadyExists) 648 return ok 649} 650 651func (err ErrTagAlreadyExists) Error() string { 652 return fmt.Sprintf("tag already exists [name: %s]", err.TagName) 653} 654 655// ErrSHADoesNotMatch represents a "SHADoesNotMatch" kind of error. 656type ErrSHADoesNotMatch struct { 657 Path string 658 GivenSHA string 659 CurrentSHA string 660} 661 662// IsErrSHADoesNotMatch checks if an error is a ErrSHADoesNotMatch. 663func IsErrSHADoesNotMatch(err error) bool { 664 _, ok := err.(ErrSHADoesNotMatch) 665 return ok 666} 667 668func (err ErrSHADoesNotMatch) Error() string { 669 return fmt.Sprintf("sha does not match [given: %s, expected: %s]", err.GivenSHA, err.CurrentSHA) 670} 671 672// ErrSHANotFound represents a "SHADoesNotMatch" kind of error. 673type ErrSHANotFound struct { 674 SHA string 675} 676 677// IsErrSHANotFound checks if an error is a ErrSHANotFound. 678func IsErrSHANotFound(err error) bool { 679 _, ok := err.(ErrSHANotFound) 680 return ok 681} 682 683func (err ErrSHANotFound) Error() string { 684 return fmt.Sprintf("sha not found [%s]", err.SHA) 685} 686 687// ErrCommitIDDoesNotMatch represents a "CommitIDDoesNotMatch" kind of error. 688type ErrCommitIDDoesNotMatch struct { 689 GivenCommitID string 690 CurrentCommitID string 691} 692 693// IsErrCommitIDDoesNotMatch checks if an error is a ErrCommitIDDoesNotMatch. 694func IsErrCommitIDDoesNotMatch(err error) bool { 695 _, ok := err.(ErrCommitIDDoesNotMatch) 696 return ok 697} 698 699func (err ErrCommitIDDoesNotMatch) Error() string { 700 return fmt.Sprintf("file CommitID does not match [given: %s, expected: %s]", err.GivenCommitID, err.CurrentCommitID) 701} 702 703// ErrSHAOrCommitIDNotProvided represents a "SHAOrCommitIDNotProvided" kind of error. 704type ErrSHAOrCommitIDNotProvided struct{} 705 706// IsErrSHAOrCommitIDNotProvided checks if an error is a ErrSHAOrCommitIDNotProvided. 707func IsErrSHAOrCommitIDNotProvided(err error) bool { 708 _, ok := err.(ErrSHAOrCommitIDNotProvided) 709 return ok 710} 711 712func (err ErrSHAOrCommitIDNotProvided) Error() string { 713 return "a SHA or commit ID must be proved when updating a file" 714} 715 716// .___ 717// | | ______ ________ __ ____ 718// | |/ ___// ___/ | \_/ __ \ 719// | |\___ \ \___ \| | /\ ___/ 720// |___/____ >____ >____/ \___ > 721// \/ \/ \/ 722 723// ErrIssueNotExist represents a "IssueNotExist" kind of error. 724type ErrIssueNotExist struct { 725 ID int64 726 RepoID int64 727 Index int64 728} 729 730// IsErrIssueNotExist checks if an error is a ErrIssueNotExist. 731func IsErrIssueNotExist(err error) bool { 732 _, ok := err.(ErrIssueNotExist) 733 return ok 734} 735 736func (err ErrIssueNotExist) Error() string { 737 return fmt.Sprintf("issue does not exist [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index) 738} 739 740// ErrIssueIsClosed represents a "IssueIsClosed" kind of error. 741type ErrIssueIsClosed struct { 742 ID int64 743 RepoID int64 744 Index int64 745} 746 747// IsErrIssueIsClosed checks if an error is a ErrIssueNotExist. 748func IsErrIssueIsClosed(err error) bool { 749 _, ok := err.(ErrIssueIsClosed) 750 return ok 751} 752 753func (err ErrIssueIsClosed) Error() string { 754 return fmt.Sprintf("issue is closed [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index) 755} 756 757// ErrIssueLabelTemplateLoad represents a "ErrIssueLabelTemplateLoad" kind of error. 758type ErrIssueLabelTemplateLoad struct { 759 TemplateFile string 760 OriginalError error 761} 762 763// IsErrIssueLabelTemplateLoad checks if an error is a ErrIssueLabelTemplateLoad. 764func IsErrIssueLabelTemplateLoad(err error) bool { 765 _, ok := err.(ErrIssueLabelTemplateLoad) 766 return ok 767} 768 769func (err ErrIssueLabelTemplateLoad) Error() string { 770 return fmt.Sprintf("Failed to load label template file '%s': %v", err.TemplateFile, err.OriginalError) 771} 772 773// ErrNewIssueInsert is used when the INSERT statement in newIssue fails 774type ErrNewIssueInsert struct { 775 OriginalError error 776} 777 778// IsErrNewIssueInsert checks if an error is a ErrNewIssueInsert. 779func IsErrNewIssueInsert(err error) bool { 780 _, ok := err.(ErrNewIssueInsert) 781 return ok 782} 783 784func (err ErrNewIssueInsert) Error() string { 785 return err.OriginalError.Error() 786} 787 788// ErrIssueWasClosed is used when close a closed issue 789type ErrIssueWasClosed struct { 790 ID int64 791 Index int64 792} 793 794// IsErrIssueWasClosed checks if an error is a ErrIssueWasClosed. 795func IsErrIssueWasClosed(err error) bool { 796 _, ok := err.(ErrIssueWasClosed) 797 return ok 798} 799 800func (err ErrIssueWasClosed) Error() string { 801 return fmt.Sprintf("Issue [%d] %d was already closed", err.ID, err.Index) 802} 803 804// ErrPullWasClosed is used close a closed pull request 805type ErrPullWasClosed struct { 806 ID int64 807 Index int64 808} 809 810// IsErrPullWasClosed checks if an error is a ErrErrPullWasClosed. 811func IsErrPullWasClosed(err error) bool { 812 _, ok := err.(ErrPullWasClosed) 813 return ok 814} 815 816func (err ErrPullWasClosed) Error() string { 817 return fmt.Sprintf("Pull request [%d] %d was already closed", err.ID, err.Index) 818} 819 820// ErrForbiddenIssueReaction is used when a forbidden reaction was try to created 821type ErrForbiddenIssueReaction struct { 822 Reaction string 823} 824 825// IsErrForbiddenIssueReaction checks if an error is a ErrForbiddenIssueReaction. 826func IsErrForbiddenIssueReaction(err error) bool { 827 _, ok := err.(ErrForbiddenIssueReaction) 828 return ok 829} 830 831func (err ErrForbiddenIssueReaction) Error() string { 832 return fmt.Sprintf("'%s' is not an allowed reaction", err.Reaction) 833} 834 835// ErrReactionAlreadyExist is used when a existing reaction was try to created 836type ErrReactionAlreadyExist struct { 837 Reaction string 838} 839 840// IsErrReactionAlreadyExist checks if an error is a ErrReactionAlreadyExist. 841func IsErrReactionAlreadyExist(err error) bool { 842 _, ok := err.(ErrReactionAlreadyExist) 843 return ok 844} 845 846func (err ErrReactionAlreadyExist) Error() string { 847 return fmt.Sprintf("reaction '%s' already exists", err.Reaction) 848} 849 850// __________ .__ .__ __________ __ 851// \______ \__ __| | | |\______ \ ____ ________ __ ____ _______/ |_ 852// | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\ 853// | | | | / |_| |_| | \ ___< <_| | | /\ ___/ \___ \ | | 854// |____| |____/|____/____/____|_ /\___ >__ |____/ \___ >____ > |__| 855// \/ \/ |__| \/ \/ 856 857// ErrPullRequestNotExist represents a "PullRequestNotExist" kind of error. 858type ErrPullRequestNotExist struct { 859 ID int64 860 IssueID int64 861 HeadRepoID int64 862 BaseRepoID int64 863 HeadBranch string 864 BaseBranch string 865} 866 867// IsErrPullRequestNotExist checks if an error is a ErrPullRequestNotExist. 868func IsErrPullRequestNotExist(err error) bool { 869 _, ok := err.(ErrPullRequestNotExist) 870 return ok 871} 872 873func (err ErrPullRequestNotExist) Error() string { 874 return fmt.Sprintf("pull request does not exist [id: %d, issue_id: %d, head_repo_id: %d, base_repo_id: %d, head_branch: %s, base_branch: %s]", 875 err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch) 876} 877 878// ErrPullRequestAlreadyExists represents a "PullRequestAlreadyExists"-error 879type ErrPullRequestAlreadyExists struct { 880 ID int64 881 IssueID int64 882 HeadRepoID int64 883 BaseRepoID int64 884 HeadBranch string 885 BaseBranch string 886} 887 888// IsErrPullRequestAlreadyExists checks if an error is a ErrPullRequestAlreadyExists. 889func IsErrPullRequestAlreadyExists(err error) bool { 890 _, ok := err.(ErrPullRequestAlreadyExists) 891 return ok 892} 893 894// Error does pretty-printing :D 895func (err ErrPullRequestAlreadyExists) Error() string { 896 return fmt.Sprintf("pull request already exists for these targets [id: %d, issue_id: %d, head_repo_id: %d, base_repo_id: %d, head_branch: %s, base_branch: %s]", 897 err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch) 898} 899 900// ErrPullRequestHeadRepoMissing represents a "ErrPullRequestHeadRepoMissing" error 901type ErrPullRequestHeadRepoMissing struct { 902 ID int64 903 HeadRepoID int64 904} 905 906// IsErrErrPullRequestHeadRepoMissing checks if an error is a ErrPullRequestHeadRepoMissing. 907func IsErrErrPullRequestHeadRepoMissing(err error) bool { 908 _, ok := err.(ErrPullRequestHeadRepoMissing) 909 return ok 910} 911 912// Error does pretty-printing :D 913func (err ErrPullRequestHeadRepoMissing) Error() string { 914 return fmt.Sprintf("pull request head repo missing [id: %d, head_repo_id: %d]", 915 err.ID, err.HeadRepoID) 916} 917 918// ErrInvalidMergeStyle represents an error if merging with disabled merge strategy 919type ErrInvalidMergeStyle struct { 920 ID int64 921 Style repo_model.MergeStyle 922} 923 924// IsErrInvalidMergeStyle checks if an error is a ErrInvalidMergeStyle. 925func IsErrInvalidMergeStyle(err error) bool { 926 _, ok := err.(ErrInvalidMergeStyle) 927 return ok 928} 929 930func (err ErrInvalidMergeStyle) Error() string { 931 return fmt.Sprintf("merge strategy is not allowed or is invalid [repo_id: %d, strategy: %s]", 932 err.ID, err.Style) 933} 934 935// ErrMergeConflicts represents an error if merging fails with a conflict 936type ErrMergeConflicts struct { 937 Style repo_model.MergeStyle 938 StdOut string 939 StdErr string 940 Err error 941} 942 943// IsErrMergeConflicts checks if an error is a ErrMergeConflicts. 944func IsErrMergeConflicts(err error) bool { 945 _, ok := err.(ErrMergeConflicts) 946 return ok 947} 948 949func (err ErrMergeConflicts) Error() string { 950 return fmt.Sprintf("Merge Conflict Error: %v: %s\n%s", err.Err, err.StdErr, err.StdOut) 951} 952 953// ErrMergeUnrelatedHistories represents an error if merging fails due to unrelated histories 954type ErrMergeUnrelatedHistories struct { 955 Style repo_model.MergeStyle 956 StdOut string 957 StdErr string 958 Err error 959} 960 961// IsErrMergeUnrelatedHistories checks if an error is a ErrMergeUnrelatedHistories. 962func IsErrMergeUnrelatedHistories(err error) bool { 963 _, ok := err.(ErrMergeUnrelatedHistories) 964 return ok 965} 966 967func (err ErrMergeUnrelatedHistories) Error() string { 968 return fmt.Sprintf("Merge UnrelatedHistories Error: %v: %s\n%s", err.Err, err.StdErr, err.StdOut) 969} 970 971// ErrRebaseConflicts represents an error if rebase fails with a conflict 972type ErrRebaseConflicts struct { 973 Style repo_model.MergeStyle 974 CommitSHA string 975 StdOut string 976 StdErr string 977 Err error 978} 979 980// IsErrRebaseConflicts checks if an error is a ErrRebaseConflicts. 981func IsErrRebaseConflicts(err error) bool { 982 _, ok := err.(ErrRebaseConflicts) 983 return ok 984} 985 986func (err ErrRebaseConflicts) Error() string { 987 return fmt.Sprintf("Rebase Error: %v: Whilst Rebasing: %s\n%s\n%s", err.Err, err.CommitSHA, err.StdErr, err.StdOut) 988} 989 990// ErrPullRequestHasMerged represents a "PullRequestHasMerged"-error 991type ErrPullRequestHasMerged struct { 992 ID int64 993 IssueID int64 994 HeadRepoID int64 995 BaseRepoID int64 996 HeadBranch string 997 BaseBranch string 998} 999 1000// IsErrPullRequestHasMerged checks if an error is a ErrPullRequestHasMerged. 1001func IsErrPullRequestHasMerged(err error) bool { 1002 _, ok := err.(ErrPullRequestHasMerged) 1003 return ok 1004} 1005 1006// Error does pretty-printing :D 1007func (err ErrPullRequestHasMerged) Error() string { 1008 return fmt.Sprintf("pull request has merged [id: %d, issue_id: %d, head_repo_id: %d, base_repo_id: %d, head_branch: %s, base_branch: %s]", 1009 err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch) 1010} 1011 1012// _________ __ 1013// \_ ___ \ ____ _____ _____ ____ _____/ |_ 1014// / \ \/ / _ \ / \ / \_/ __ \ / \ __\ 1015// \ \___( <_> ) Y Y \ Y Y \ ___/| | \ | 1016// \______ /\____/|__|_| /__|_| /\___ >___| /__| 1017// \/ \/ \/ \/ \/ 1018 1019// ErrCommentNotExist represents a "CommentNotExist" kind of error. 1020type ErrCommentNotExist struct { 1021 ID int64 1022 IssueID int64 1023} 1024 1025// IsErrCommentNotExist checks if an error is a ErrCommentNotExist. 1026func IsErrCommentNotExist(err error) bool { 1027 _, ok := err.(ErrCommentNotExist) 1028 return ok 1029} 1030 1031func (err ErrCommentNotExist) Error() string { 1032 return fmt.Sprintf("comment does not exist [id: %d, issue_id: %d]", err.ID, err.IssueID) 1033} 1034 1035// _________ __ __ .__ 1036// / _____// |_ ____ ________ _ _______ _/ |_ ____ | |__ 1037// \_____ \\ __\/ _ \\____ \ \/ \/ /\__ \\ __\/ ___\| | \ 1038// / \| | ( <_> ) |_> > / / __ \| | \ \___| Y \ 1039// /_______ /|__| \____/| __/ \/\_/ (____ /__| \___ >___| / 1040// \/ |__| \/ \/ \/ 1041 1042// ErrStopwatchNotExist represents a "Stopwatch Not Exist" kind of error. 1043type ErrStopwatchNotExist struct { 1044 ID int64 1045} 1046 1047// IsErrStopwatchNotExist checks if an error is a ErrStopwatchNotExist. 1048func IsErrStopwatchNotExist(err error) bool { 1049 _, ok := err.(ErrStopwatchNotExist) 1050 return ok 1051} 1052 1053func (err ErrStopwatchNotExist) Error() string { 1054 return fmt.Sprintf("stopwatch does not exist [id: %d]", err.ID) 1055} 1056 1057// ___________ __ .______________.__ 1058// \__ ___/___________ ____ | | __ ____ __| _/\__ ___/|__| _____ ____ 1059// | | \_ __ \__ \ _/ ___\| |/ // __ \ / __ | | | | |/ \_/ __ \ 1060// | | | | \// __ \\ \___| <\ ___// /_/ | | | | | Y Y \ ___/ 1061// |____| |__| (____ /\___ >__|_ \\___ >____ | |____| |__|__|_| /\___ > 1062// \/ \/ \/ \/ \/ \/ \/ 1063 1064// ErrTrackedTimeNotExist represents a "TrackedTime Not Exist" kind of error. 1065type ErrTrackedTimeNotExist struct { 1066 ID int64 1067} 1068 1069// IsErrTrackedTimeNotExist checks if an error is a ErrTrackedTimeNotExist. 1070func IsErrTrackedTimeNotExist(err error) bool { 1071 _, ok := err.(ErrTrackedTimeNotExist) 1072 return ok 1073} 1074 1075func (err ErrTrackedTimeNotExist) Error() string { 1076 return fmt.Sprintf("tracked time does not exist [id: %d]", err.ID) 1077} 1078 1079// .____ ___. .__ 1080// | | _____ \_ |__ ____ | | 1081// | | \__ \ | __ \_/ __ \| | 1082// | |___ / __ \| \_\ \ ___/| |__ 1083// |_______ (____ /___ /\___ >____/ 1084// \/ \/ \/ \/ 1085 1086// ErrRepoLabelNotExist represents a "RepoLabelNotExist" kind of error. 1087type ErrRepoLabelNotExist struct { 1088 LabelID int64 1089 RepoID int64 1090} 1091 1092// IsErrRepoLabelNotExist checks if an error is a RepoErrLabelNotExist. 1093func IsErrRepoLabelNotExist(err error) bool { 1094 _, ok := err.(ErrRepoLabelNotExist) 1095 return ok 1096} 1097 1098func (err ErrRepoLabelNotExist) Error() string { 1099 return fmt.Sprintf("label does not exist [label_id: %d, repo_id: %d]", err.LabelID, err.RepoID) 1100} 1101 1102// ErrOrgLabelNotExist represents a "OrgLabelNotExist" kind of error. 1103type ErrOrgLabelNotExist struct { 1104 LabelID int64 1105 OrgID int64 1106} 1107 1108// IsErrOrgLabelNotExist checks if an error is a OrgErrLabelNotExist. 1109func IsErrOrgLabelNotExist(err error) bool { 1110 _, ok := err.(ErrOrgLabelNotExist) 1111 return ok 1112} 1113 1114func (err ErrOrgLabelNotExist) Error() string { 1115 return fmt.Sprintf("label does not exist [label_id: %d, org_id: %d]", err.LabelID, err.OrgID) 1116} 1117 1118// ErrLabelNotExist represents a "LabelNotExist" kind of error. 1119type ErrLabelNotExist struct { 1120 LabelID int64 1121} 1122 1123// IsErrLabelNotExist checks if an error is a ErrLabelNotExist. 1124func IsErrLabelNotExist(err error) bool { 1125 _, ok := err.(ErrLabelNotExist) 1126 return ok 1127} 1128 1129func (err ErrLabelNotExist) Error() string { 1130 return fmt.Sprintf("label does not exist [label_id: %d]", err.LabelID) 1131} 1132 1133// __________ __ __ 1134// \______ \_______ ____ |__| ____ _____/ |_ ______ 1135// | ___/\_ __ \/ _ \ | |/ __ \_/ ___\ __\/ ___/ 1136// | | | | \( <_> ) | \ ___/\ \___| | \___ \ 1137// |____| |__| \____/\__| |\___ >\___ >__| /____ > 1138// \______| \/ \/ \/ 1139 1140// ErrProjectNotExist represents a "ProjectNotExist" kind of error. 1141type ErrProjectNotExist struct { 1142 ID int64 1143 RepoID int64 1144} 1145 1146// IsErrProjectNotExist checks if an error is a ErrProjectNotExist 1147func IsErrProjectNotExist(err error) bool { 1148 _, ok := err.(ErrProjectNotExist) 1149 return ok 1150} 1151 1152func (err ErrProjectNotExist) Error() string { 1153 return fmt.Sprintf("projects does not exist [id: %d]", err.ID) 1154} 1155 1156// ErrProjectBoardNotExist represents a "ProjectBoardNotExist" kind of error. 1157type ErrProjectBoardNotExist struct { 1158 BoardID int64 1159} 1160 1161// IsErrProjectBoardNotExist checks if an error is a ErrProjectBoardNotExist 1162func IsErrProjectBoardNotExist(err error) bool { 1163 _, ok := err.(ErrProjectBoardNotExist) 1164 return ok 1165} 1166 1167func (err ErrProjectBoardNotExist) Error() string { 1168 return fmt.Sprintf("project board does not exist [id: %d]", err.BoardID) 1169} 1170 1171// _____ .__.__ __ 1172// / \ |__| | ____ _______/ |_ ____ ____ ____ 1173// / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \ 1174// / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/ 1175// \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ > 1176// \/ \/ \/ \/ \/ 1177 1178// ErrMilestoneNotExist represents a "MilestoneNotExist" kind of error. 1179type ErrMilestoneNotExist struct { 1180 ID int64 1181 RepoID int64 1182 Name string 1183} 1184 1185// IsErrMilestoneNotExist checks if an error is a ErrMilestoneNotExist. 1186func IsErrMilestoneNotExist(err error) bool { 1187 _, ok := err.(ErrMilestoneNotExist) 1188 return ok 1189} 1190 1191func (err ErrMilestoneNotExist) Error() string { 1192 if len(err.Name) > 0 { 1193 return fmt.Sprintf("milestone does not exist [name: %s, repo_id: %d]", err.Name, err.RepoID) 1194 } 1195 return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID) 1196} 1197 1198// ___________ 1199// \__ ___/___ _____ _____ 1200// | |_/ __ \\__ \ / \ 1201// | |\ ___/ / __ \| Y Y \ 1202// |____| \___ >____ /__|_| / 1203// \/ \/ \/ 1204 1205// ErrTeamAlreadyExist represents a "TeamAlreadyExist" kind of error. 1206type ErrTeamAlreadyExist struct { 1207 OrgID int64 1208 Name string 1209} 1210 1211// IsErrTeamAlreadyExist checks if an error is a ErrTeamAlreadyExist. 1212func IsErrTeamAlreadyExist(err error) bool { 1213 _, ok := err.(ErrTeamAlreadyExist) 1214 return ok 1215} 1216 1217func (err ErrTeamAlreadyExist) Error() string { 1218 return fmt.Sprintf("team already exists [org_id: %d, name: %s]", err.OrgID, err.Name) 1219} 1220 1221// ErrTeamNotExist represents a "TeamNotExist" error 1222type ErrTeamNotExist struct { 1223 OrgID int64 1224 TeamID int64 1225 Name string 1226} 1227 1228// IsErrTeamNotExist checks if an error is a ErrTeamNotExist. 1229func IsErrTeamNotExist(err error) bool { 1230 _, ok := err.(ErrTeamNotExist) 1231 return ok 1232} 1233 1234func (err ErrTeamNotExist) Error() string { 1235 return fmt.Sprintf("team does not exist [org_id %d, team_id %d, name: %s]", err.OrgID, err.TeamID, err.Name) 1236} 1237 1238// ____ ___ .__ .___ 1239// | | \______ | | _________ __| _/ 1240// | | /\____ \| | / _ \__ \ / __ | 1241// | | / | |_> > |_( <_> ) __ \_/ /_/ | 1242// |______/ | __/|____/\____(____ /\____ | 1243// |__| \/ \/ 1244// 1245 1246// ErrUploadNotExist represents a "UploadNotExist" kind of error. 1247type ErrUploadNotExist struct { 1248 ID int64 1249 UUID string 1250} 1251 1252// IsErrUploadNotExist checks if an error is a ErrUploadNotExist. 1253func IsErrUploadNotExist(err error) bool { 1254 _, ok := err.(ErrUploadNotExist) 1255 return ok 1256} 1257 1258func (err ErrUploadNotExist) Error() string { 1259 return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID) 1260} 1261 1262// .___ ________ .___ .__ 1263// | | ______ ________ __ ____ \______ \ ____ ______ ____ ____ __| _/____ ____ ____ |__| ____ ______ 1264// | |/ ___// ___/ | \_/ __ \ | | \_/ __ \\____ \_/ __ \ / \ / __ |/ __ \ / \_/ ___\| |/ __ \ / ___/ 1265// | |\___ \ \___ \| | /\ ___/ | ` \ ___/| |_> > ___/| | \/ /_/ \ ___/| | \ \___| \ ___/ \___ \ 1266// |___/____ >____ >____/ \___ >_______ /\___ > __/ \___ >___| /\____ |\___ >___| /\___ >__|\___ >____ > 1267// \/ \/ \/ \/ \/|__| \/ \/ \/ \/ \/ \/ \/ \/ 1268 1269// ErrDependencyExists represents a "DependencyAlreadyExists" kind of error. 1270type ErrDependencyExists struct { 1271 IssueID int64 1272 DependencyID int64 1273} 1274 1275// IsErrDependencyExists checks if an error is a ErrDependencyExists. 1276func IsErrDependencyExists(err error) bool { 1277 _, ok := err.(ErrDependencyExists) 1278 return ok 1279} 1280 1281func (err ErrDependencyExists) Error() string { 1282 return fmt.Sprintf("issue dependency does already exist [issue id: %d, dependency id: %d]", err.IssueID, err.DependencyID) 1283} 1284 1285// ErrDependencyNotExists represents a "DependencyAlreadyExists" kind of error. 1286type ErrDependencyNotExists struct { 1287 IssueID int64 1288 DependencyID int64 1289} 1290 1291// IsErrDependencyNotExists checks if an error is a ErrDependencyExists. 1292func IsErrDependencyNotExists(err error) bool { 1293 _, ok := err.(ErrDependencyNotExists) 1294 return ok 1295} 1296 1297func (err ErrDependencyNotExists) Error() string { 1298 return fmt.Sprintf("issue dependency does not exist [issue id: %d, dependency id: %d]", err.IssueID, err.DependencyID) 1299} 1300 1301// ErrCircularDependency represents a "DependencyCircular" kind of error. 1302type ErrCircularDependency struct { 1303 IssueID int64 1304 DependencyID int64 1305} 1306 1307// IsErrCircularDependency checks if an error is a ErrCircularDependency. 1308func IsErrCircularDependency(err error) bool { 1309 _, ok := err.(ErrCircularDependency) 1310 return ok 1311} 1312 1313func (err ErrCircularDependency) Error() string { 1314 return fmt.Sprintf("circular dependencies exists (two issues blocking each other) [issue id: %d, dependency id: %d]", err.IssueID, err.DependencyID) 1315} 1316 1317// ErrDependenciesLeft represents an error where the issue you're trying to close still has dependencies left. 1318type ErrDependenciesLeft struct { 1319 IssueID int64 1320} 1321 1322// IsErrDependenciesLeft checks if an error is a ErrDependenciesLeft. 1323func IsErrDependenciesLeft(err error) bool { 1324 _, ok := err.(ErrDependenciesLeft) 1325 return ok 1326} 1327 1328func (err ErrDependenciesLeft) Error() string { 1329 return fmt.Sprintf("issue has open dependencies [issue id: %d]", err.IssueID) 1330} 1331 1332// ErrUnknownDependencyType represents an error where an unknown dependency type was passed 1333type ErrUnknownDependencyType struct { 1334 Type DependencyType 1335} 1336 1337// IsErrUnknownDependencyType checks if an error is ErrUnknownDependencyType 1338func IsErrUnknownDependencyType(err error) bool { 1339 _, ok := err.(ErrUnknownDependencyType) 1340 return ok 1341} 1342 1343func (err ErrUnknownDependencyType) Error() string { 1344 return fmt.Sprintf("unknown dependency type [type: %d]", err.Type) 1345} 1346 1347// __________ .__ 1348// \______ \ _______ _|__| ______ _ __ 1349// | _// __ \ \/ / |/ __ \ \/ \/ / 1350// | | \ ___/\ /| \ ___/\ / 1351// |____|_ /\___ >\_/ |__|\___ >\/\_/ 1352// \/ \/ \/ 1353 1354// ErrReviewNotExist represents a "ReviewNotExist" kind of error. 1355type ErrReviewNotExist struct { 1356 ID int64 1357} 1358 1359// IsErrReviewNotExist checks if an error is a ErrReviewNotExist. 1360func IsErrReviewNotExist(err error) bool { 1361 _, ok := err.(ErrReviewNotExist) 1362 return ok 1363} 1364 1365func (err ErrReviewNotExist) Error() string { 1366 return fmt.Sprintf("review does not exist [id: %d]", err.ID) 1367} 1368 1369// ErrNotValidReviewRequest an not allowed review request modify 1370type ErrNotValidReviewRequest struct { 1371 Reason string 1372 UserID int64 1373 RepoID int64 1374} 1375 1376// IsErrNotValidReviewRequest checks if an error is a ErrNotValidReviewRequest. 1377func IsErrNotValidReviewRequest(err error) bool { 1378 _, ok := err.(ErrNotValidReviewRequest) 1379 return ok 1380} 1381 1382func (err ErrNotValidReviewRequest) Error() string { 1383 return fmt.Sprintf("%s [user_id: %d, repo_id: %d]", 1384 err.Reason, 1385 err.UserID, 1386 err.RepoID) 1387} 1388