{"action":"created","issue":{"url":"https://api.github.com/repos/streadway/amqp/issues/186","repository_url":"https://api.github.com/repos/streadway/amqp","labels_url":"https://api.github.com/repos/streadway/amqp/issues/186/labels{/name}","comments_url":"https://api.github.com/repos/streadway/amqp/issues/186/comments","events_url":"https://api.github.com/repos/streadway/amqp/issues/186/events","html_url":"https://github.com/streadway/amqp/issues/186","id":132862585,"number":186,"title":"Publishing to bad exchange causes Error instead of Return","user":{"login":"zombor","id":170538,"avatar_url":"https://avatars.githubusercontent.com/u/170538?v=3","gravatar_id":"","url":"https://api.github.com/users/zombor","html_url":"https://github.com/zombor","followers_url":"https://api.github.com/users/zombor/followers","following_url":"https://api.github.com/users/zombor/following{/other_user}","gists_url":"https://api.github.com/users/zombor/gists{/gist_id}","starred_url":"https://api.github.com/users/zombor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zombor/subscriptions","organizations_url":"https://api.github.com/users/zombor/orgs","repos_url":"https://api.github.com/users/zombor/repos","events_url":"https://api.github.com/users/zombor/events{/privacy}","received_events_url":"https://api.github.com/users/zombor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-11T00:51:16Z","updated_at":"2016-02-11T02:08:59Z","closed_at":null,"body":"I have the following program that publishes to a missing exchange. I expected a `Return` to come back, but I get an `Error` instead.\r\n\r\nIs this expected? The documentation for `NotifyReturn` says: `These can be sent from the server when a publish is undeliverable either from the mandatory or immediate flags.`\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n        \"fmt\"\r\n\r\n        \"github.com/streadway/amqp\"\r\n)\r\n\r\nfunc main() {\r\n        conn, err := amqp.Dial(\"amqp://guest:guest@localhost\")\r\n        if err != nil {\r\n                panic(err)\r\n        }\r\n\r\n        ch, err := conn.Channel()\r\n        if err != nil {\r\n                panic(err)\r\n        }\r\n\r\n        if err := ch.Confirm(false); err != nil {\r\n                panic(err)\r\n        }\r\n\r\n        errs := ch.NotifyClose(make(chan *amqp.Error, 1))\r\n        returns := ch.NotifyReturn(make(chan amqp.Return, 1))\r\n\r\n        if err := ch.Publish(\r\n                \"exchangeDoesNotExist\",\r\n                \"my-routing-key\",\r\n                true,\r\n                false,\r\n                amqp.Publishing{\r\n                        ContentType: \"application/json\",\r\n                        Body:        []byte(`{\"foo\":\"bar\"}`),\r\n                },\r\n        ); err != nil {\r\n                panic(err)\r\n        }\r\n\r\n        fmt.Printf(\"Returns: %#v\\n\", <-returns)\r\n        fmt.Printf(\"Errors: %#v\\n\", <-errs)\r\n}\r\n```\r\n\r\nThe output of this program is:\r\n\r\n```\r\nReturns: amqp.Return{ReplyCode:0x0, ReplyText:\"\", Exchange:\"\", RoutingKey:\"\", ContentType:\"\", ContentEncoding:\"\", Headers:amqp.Table(nil), DeliveryMode:0x0, Priority:0x0, CorrelationId:\"\", ReplyTo:\"\", Expiration:\"\", MessageId:\"\", Timestamp:time.Time{sec:0, nsec:0, loc:(*time.Location)(nil)}, Type:\"\", UserId:\"\", AppId:\"\", Body:[]uint8(nil)}\r\nErrors: &amqp.Error{Code:404, Reason:\"NOT_FOUND - no exchange 'exchangeDoesNotExist' in vhost '/'\", Server:true, Recover:true}\r\n```\r\n\r\nThis causes the channel to be closed as well."},"comment":{"url":"https://api.github.com/repos/streadway/amqp/issues/comments/182672871","html_url":"https://github.com/streadway/amqp/issues/186#issuecomment-182672871","issue_url":"https://api.github.com/repos/streadway/amqp/issues/186","id":182672871,"user":{"login":"michaelklishin","id":1090,"avatar_url":"https://avatars.githubusercontent.com/u/1090?v=3","gravatar_id":"","url":"https://api.github.com/users/michaelklishin","html_url":"https://github.com/michaelklishin","followers_url":"https://api.github.com/users/michaelklishin/followers","following_url":"https://api.github.com/users/michaelklishin/following{/other_user}","gists_url":"https://api.github.com/users/michaelklishin/gists{/gist_id}","starred_url":"https://api.github.com/users/michaelklishin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaelklishin/subscriptions","organizations_url":"https://api.github.com/users/michaelklishin/orgs","repos_url":"https://api.github.com/users/michaelklishin/repos","events_url":"https://api.github.com/users/michaelklishin/events{/privacy}","received_events_url":"https://api.github.com/users/michaelklishin/received_events","type":"User","site_admin":false},"created_at":"2016-02-11T02:08:59Z","updated_at":"2016-02-11T02:08:59Z","body":"Publishing to an exchange that doesn't exist is a channel-level exception in the protocol, so returning an error makes sense while returning a `basic.return` is impossible."}}